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

我要举报自己的程序,没过样例也AC了.......

Posted by jiyanmoyu at 2010-03-01 00:22:15 on Problem 3243
程序代码如下,请加强数据!
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
using namespace std;
#include<fstream>
#include<algorithm>
typedef long long lld;
lld mul_mod(lld a,lld b,lld n)// a*b%n
{
    lld res=0;
    a=a%n,b=b%n;
    while(b>0)
    {
        if(b&0x01)
          res=(res+a)%n;
        a=(a+a)%n;
        b>>=1;
    }
    return res;
}
lld exp_mod(lld a,lld b,lld n)// a^b%n
{
    lld res=1%n;
    while(b>0)
    {
         if(b&0x01)
           res=mul_mod(res,a,n);
         a=mul_mod(a,a,n);
         b>>=1;
    }
    return res;
}
struct hash
{
       lld j,xj;
       bool operator<(const hash &other)const
       {
            if(xj==other.xj)
              return j>other.j;
            return xj<other.xj;
       }
};
hash table[100000];
inline bool cmp2(const hash &h1,const hash &h2)
{
       return h1.xj<h2.xj;
}
int main()
{
    long long x,z,k;
    while(cin>>x>>z>>k)
    {
          if(0==x&&0==z&&0==k)
            break;
          x=x%z;
          k=k%z;
          lld m=(lld)ceil(sqrt((double)z))+1;
          lld xj=k%z;
          lld j;
          for(j=0;j<m;++j)
          {
              table[j].j=j;
              table[j].xj=xj;
              xj=xj*x%z;
          }
          sort(table,table+m);
          lld xm=exp_mod(x,m,z);
          lld i;
          lld left=1%z;
          bool getAns=false;
          for(i=1;i<=m;++i)
          {
              left=left*xm%z;
              hash tmp;
              tmp.xj=left;
              hash *p=lower_bound(table,table+m,tmp,cmp2);
              if(p!=table+m&&(*p).xj==left)
              {
                 j=(*p).j;
               //  cout<<"i,j="<<i<<" "<<j<<endl;
                 getAns=true;
                 break;
              }
          }
          if(getAns)
            cout<<i*m-j<<endl;
          else
             cout<<"No Solution"<<endl;
    }
}

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