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 |
看似一样的程序,不一样的结果,完全不理解!!AC代码 #include <stdio.h> #define MAX(a,b) a>b?a:b int vis[16000010]; int main() { int i,a,c,m,t,ans=0; scanf("%d %d %d %d",&a,&c,&m,&t); vis[t]=1; while(1) { t=(a*t+c)%m; if(vis[t]) break; vis[t]=1; } // for(i=0;i<m;i++) if(vis[i]) break; t=i; for(i=i+1;i<m;i++) if(vis[i]) { ans=MAX(ans,i-t); t=i; } // printf("%d\n",ans); return 0; } WA代码 #include <stdio.h> #define MAX(a,b) a>b?a:b int vis[16000010]; int main() { int i,a,c,m,t,ans=0; scanf("%d %d %d %d",&a,&c,&m,&t); vis[t]=1; while(1) { t=(a*t+c)%m; if(vis[t]) break; vis[t]=1; } // for(t=i=0;i<m;i++) if(vis[i]) { if(t) ans=MAX(ans,i-t); t=i; } // printf("%d\n",ans); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator