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 |
why? 这题的测试数据是不是 有很多特例?怎么给的数据都可以正常输出,就是不让Accept. 那位高手给看看俺的代码,多谢!! #include <iostream> using namespace std; void calc(int,int); int s,dx,dy; int loop; int ix,iy; int qx,qy; void main() { cin>>s>>qx>>qy>>dx>>dy; while(s!=0||qx!=0||qy!=0||dx!=0||dy!=0) { loop=0; int xx=qx,yy=qy; while(xx>=s&&yy>=s) { xx-=s; yy-=s; } if(xx<s) while(yy>=2*s) yy-=2*s; else while(xx>=2*s) xx-=2*s; ix=xx; iy=yy; calc(qx,qy); cin>>s>>qx>>qy>>dx>>dy; } } void calc(int x,int y) { int tx=x,ty=y; while(tx>=s&&ty>=s) { tx-=s; ty-=s; } if(tx<s) while(ty>=2*s) ty-=2*s; else while(tx>=2*s) tx-=2*s; if(tx==ix&&ty==iy&&loop!=0) { cout<<"The flea cannot escape from black squares."<<endl; return; } loop++; if(tx<s) { if(ty<2*s&&ty>s) cout<<"After "<<loop-1<<" jumps the flea lands at ("<<qx+dx*(loop-1)<<", "<<qy+dy*(loop-1)<<")."<<endl; else calc(x+dx,y+dy); return; } else { if(tx<2*s&&tx>s) cout<<"After "<<loop-1<<" jumps the flea lands at ("<<qx+dx*(loop-1)<<", "<<qy+dy*(loop-1)<<")."<<endl; else calc(x+dx,y+dy); return; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator