Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why TLE ? Help !难道什么地方死循环了吗? #include<stdio.h> int n,t; struct node { double sum,curr,max; }task[101]; void solve() { int i,m,flag[101],num; double time[101],temp[101],min,rest,ave; for (i=1;i<=n;i++) { time[i]=0; flag[i]=1; } m=n; while (m) { min=1e10; for (i=1;i<=n;i++) if (flag[i]) { if (task[i].curr!=0) temp[i]=task[i].sum/task[i].curr; else temp[i]=1e20; if (temp[i]<min) min=temp[i]; } for (i=1;i<=n;i++) if (flag[i]) { task[i].sum-=min*task[i].curr; time[i]+=min; } for (i=1;i<=n;i++) if (flag[i]&&temp[i]==min) { m--; flag[i]=0; } rest=t; for (i=1;i<=n;i++) if (flag[i]) rest-=task[i].curr; while (rest) { num=0; for (i=1;i<=n;i++) if (flag[i]&&task[i].curr<task[i].max) num++; if (num==0) break; ave=rest/num; for (i=1;i<=n;i++) if (flag[i]&&task[i].curr<task[i].max) { if (task[i].curr+ave<=task[i].max) { task[i].curr=task[i].curr+ave; rest-=ave; } else { task[i].curr=task[i].max; rest-=task[i].max-task[i].curr; } } } } for (i=1;i<=n;i++) printf("NO%d:%.3llfs\n",i,time[i]); } int main() { int i,kth=0;; while (scanf("%d",&n)&&n) { scanf("%d",&t); for (i=1;i<=n;i++) scanf("%llf%llf%llf",&task[i].sum,&task[i].curr,&task[i].max); printf("Case %d:\n",++kth); solve(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator