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 |
TLE了!怎么才能提高运算速度啊?有什么简便方法看出没出现过么?#include<stdio.h> #include<math.h> int num[500000]; void main(){ int n,i,j; scanf("%d",&n); while(n!=-1){ num[0]=0; for(i=1;i<=n;i++){ num[i]=num[i-1]-i; if(num[i]<0) num[i]=num[i-1]+i; else for(j=0;j<i;j++) if(num[i]==num[j]){ num[i]=num[i-1]+i; break; } } printf("%d\n",num[n]); scanf("%d",&n); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator