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

高手给看看吧!!!!!!!!!!!!!!!!!111

Posted by wzq04 at 2005-08-27 11:02:34 on Problem 1728
#include<iostream.h>
struct pos
{
    int x;
    int y;
    pos *next;
};
int searchsame(pos *p,int x,int y)
{
    while(p!=NULL)
    {
        if(x==p->x && y==p->y)return 1;
        p=p->next;
    }
    return 0;
}
int main(void)
{
    int S,x,y,dx,dy;
    while(cin>>S>>x>>y>>dx>>dy)
    {
        if(S==0 && x==0 && y==0 && dx==0 && dy==0)break;
        int f=1;
        int num=0;
        int t1=x/S;
        int t2=y/S;
        
        pos * p=NULL;
        pos *q=new pos;
        q->x=x%S;
        q->y=y%S;
        q->next=p;
        p=q;
		while((t1-t2)%2 ==0)
		{   
			num++; 
			
			x+=dx;
			y+=dy;   
			
			int re=searchsame(p,x%S,y%S);
			if(re==1){f=0;break;} 
			
			if(x%S==0 || y%S==0)continue;
			
			t1=x/S;
			t2=y/S;
			
			pos *q=new pos;
			q->x=x%S;
			q->y=y%S;
			q->next=p;
			p=q;                                        
		}
		q=p;
		while(p->next!=NULL){delete p;p=q->next;q=p;}
        if(f==1)cout<<"After "<<num<<" jumps the flea lands at ("<<x<<", "<<y<<")."<<endl;
        else cout<<"The flea cannot escape from black squares."<<endl;
	}
	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