| ||||||||||
| 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 | |||||||||
TLE 改了无数次还是不对,求解释Code :
#include <stdio.h>
int vis[1010][1010];
long long s,tx,ty;
void turn(long long x,long long y)
{
tx=x%(2*s);
ty=y%(2*s);
if(tx>s&&ty>s) tx-=s,ty-=s;
else if(tx>s&&ty%s==0) tx-=s;
else if(tx%s==0&&ty>s) ty-=s;
}
int main()
{
long long x,y,dx,dy,con,flag;
while(scanf("%I64d %I64d %I64d %I64d %I64d",&s,&x,&y,&dx,&dy))
{
if(s+x+y+dx+dy==0) break;
con=0;
memset(vis,0,sizeof(vis));
do
{
turn(x,y);
if(tx>s||ty>s) {flag=1;break;}
if(vis[tx][ty]) {flag=0;break;}
vis[tx][ty]=1;
x+=dx,y+=dy;
}while(++con);
if(flag) printf("After %I64d jumps the flea lands at (%I64d, %I64d).\n",con,x,y);
else printf("The flea cannot escape from black squares.\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