Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

看似一样的程序,不一样的结果,完全不理解!!

Posted by 2857 at 2012-08-04 21:23:16 on Problem 2381
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator