| ||||||||||
| 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 | |||||||||
Re:一次ac!两重循环,max10 000 000居然没超时。。跑了266msIn Reply To:一次ac!两重循环,max10 000 000居然没超时。。跑了266ms Posted by:kirsten0302 at 2009-08-07 18:34:38 > #include<iostream>
> using namespace std;
>
> int main ()
> {
> int i,j,k;
> int sum,count;
> while (scanf("%d",&k)!=EOF)
> {
>
> count=0;
> for (i=1;i<=k;i++)
>
> { sum=0;
> for (j=i;j<=k;j++)
> {
> sum=sum+j;
> if (sum>k) break;
> if (sum==k) {count++;continue;}
> }
>
> }
> cout<<count<<endl;
> }
> return 0;
> }
>
> 想法很普遍啊。。。。。。
第一重循环只需要到K/2即可。。。。。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator