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 |
我的程序超时,求助大牛(附代码)#include <stdio.h> #include <memory.h> #define M 1000 int used[M+5][M+5]; __int64 s,X,Y,dx,dy; __int64 fx,fy; int solve(){ __int64 x,y; int sum=0; while((X/s+Y/s)%2==0||(X%s)==0||(Y%s)==0){//如果不满足就表示已经进入了白格 x=X%s; y=Y%s; if(used[x][y]==1) return -1; used[x][y]=1; X+=dx; Y+=dy; sum++; } fx=X; fy=Y; return sum; } int main(){ scanf("%I64d%I64d%I64d%I64d%I64d",&s,&X,&Y,&dx,&dy); while(s!=0||X!=0||Y!=0||dx!=0||dy!=0){ memset(used,0,sizeof(used)); int r=solve(); if(r==-1) printf("The flea cannot escape from black squares.\n"); else printf("After %d jumps the flea lands at (%I64d, %I64d).\n",r,fx,fy); scanf("%I64d%I64d%I64d%I64d%I64d",&s,&X,&Y,&dx,&dy); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator