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

我的程序超时,求助大牛(附代码)

Posted by killer8888 at 2008-06-20 21:08:08 on Problem 1728
#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:
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