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 |
Re:超时错误,求高人指点,我是一步一个脚印跳的呢.测试数据都通过In Reply To:超时错误,求高人指点,我是一步一个脚印跳的呢.测试数据都通过 Posted by:lmsun at 2010-07-08 11:20:16 > #include<iostream> > using namespace std; > int main() > { > __int64 x,y,m,n,l; > scanf("%I64d %I64d %I64d %I64d %I64d",&x,&y,&m,&n,&l); > x = x % l; > y = y % l; > __int64 xs = x ; > __int64 ys = y ; > __int64 i = 0; > bool flag = true; > while(true) > { > if( xs == ys) break; //走到相同地的地方了,退出 > xs = (xs + m) % l; > ys = (ys + n) % l; > i++; > if(xs == x && ys == y) //回到开始位置,退出 > { > flag = false; > break; > } > } > if(flag) > printf("%I64d\n",i); > else > printf("Impossible\n"); > return 0; > } 死算是不行的。。。。前人的方法,用扩展欧几里德算法 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator