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 |
同样是暴力,为什么一个500+,一个tle呢? 麻烦大牛解释一下,谢谢啦.这个是500+的代码: #include<iostream> using namespace std; #define MAX 300 int s[MAX]; int m[MAX]; int main() { int n, g, i, j, k; scanf("%d", &n); while(n--){ scanf("%d", &g); memset(s, 0, sizeof(s)); memset(m, 0, sizeof(m)); for(i=0; i<g; i++){ scanf("%d", s+i); } for(j=1; ; j++){ for(i=0; i<g; i++){ m[i] = s[i] % j; } for(i=0; i<g; i++){ for(k=i+1; k<g; k++){ if(m[k] == m[i]) break; } if(k != g) break; } if(i == g) break; } printf("%d\n", j); } return 0; } 这个是tle的代码: #include <iostream> using namespace std; int flag[1000000]; int main() { int n, g, s[301]; int i, j, tmp; scanf("%d", &n); while(n--){ scanf("%d", &g); for(i=1; i<=g; i++) scanf("%d", s+i); for(j=1; ;j++){ memset(flag,0,sizeof(flag)); for(i=1; i<=g; i++){ tmp = s[i]%j; if(flag[tmp]) break; flag[tmp] = 1; } if(i>g) break; } printf("%d\n",j); } return 0; } 请哪位大牛解释一下.谢谢啦 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator