| ||||||||||
| 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 | |||||||||
高手给看看吧!!!!!!!!!!!!!!!!!111#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator