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 |
请教这两个程序的差异,谢谢#include<iostream> using namespace std; int d[301]; int f[1000001]; int main() { //freopen("in.txt","r",stdin); int cas,n,r,t; scanf("%d",&cas); while(cas--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&d[i]); } for(int j=n;;j++) { memset(f,-1,sizeof(f)); for(t=0;t<n;t++) { r=d[t]%j; if(f[r]>=0) { break; } else { f[r]=1; } } if(t==n) { printf("%d\n",j); break; } } } return 1; } 、、、、、、、、、、、、、、、、、、、、、、、、 #include<iostream> #include<map> using namespace std; int a[301]; int r[1000001]; //纯暴力 //搞不明白上面的是n^2logn的居然也超时 //还是暴力好 int main() { int t,n,c,i,k,flag; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(k=n;;k++) { memset(r,-1,sizeof(int)*k); c=0; for(i=1;i<=n;i++) { if(r[a[i]%k]!=-1)break; r[a[i]%k]=a[i]%k; c++; } if(c==n)break; } printf("%d\n",k); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator