Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:怎么老是Time Limit Exceeded

Posted by thomaslee at 2011-09-24 13:54:16 on Problem 1003
In Reply To:怎么老是Time Limit Exceeded Posted by:ustc911 at 2011-08-22 15:33:33
重复计算太多了,你需要用一个数组把已经计算过的结果保存下来,输入一个数c时,如果数组的最后一个数sum[maxN]大于c,就要从maxN开始继续计算;否则就遍历这个数组,找到第1个大于c的下标。

> #include<stdio.h>
> int main()
> {
> int i=0,n=1,b[10];
> float s=0.0,m=0.01,a=0.01,c[10];
> while(a!=0)
> {
> scanf("%f",&a);
> if(a>5.20) printf("input error\n");
> else {c[i]=a;i++;}
> }
> while(m>0)
> {
> s=s+1/(n+1);
> for(i=0;c[i]>0;i++)
> {
> if(c[i]<s) b[i]=n;
> m=c[i];
> }
> n++;
> }
> b[i+1]=0;
> for(i=0;b[i]>0;i++)
> printf("%5dcard(s)",b[i]);
> return 0;
> }
> 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator