题意:两只兔子在n*n的格子里移动,一只从左上角[1,1]开始,另一只从右下角[n,n]开始,然后经过一系列的条件:
1.他们可以它们可以沿东南西北4个方向走,但不可出格,各有各的速度,相遇时,两只兔子交换移动方向,碰边界时反向,各自还有自己的转左周期,周期一到即转左(但此时两只兔子相遇就不执行此周期转左),问K小时后两只兔子的坐标。
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <set>
const long long INF=(1ll<<60);
using namespace std;
struct node
{
char flag;
int x,y;
};
int main()
{
int n;
node First,Second;
int fs,ft;
int ss,st;
while(scanf("%d",&n)&&n)
{
getchar();
scanf("%c %d %d",&First.flag,&fs,&ft);
getchar();
scanf("%c %d %d",&Second.flag,&ss,&st);
First.x=1;
First.y=1;
Second.x=n;
Second.y=n;
int k;
scanf("%d",&k);
for(int i=1; i<=k; i++)
{
if(First.flag=='N')
{
First.x-=fs;
if(First.x <= 0)
{
First.x +=fs;
First.x=fs-(First.x-1)+1;
First.flag='S';
}
}
else if(First.flag=='S')
{
First.x+=fs;
if(First.x > n)
{
First.x-=fs;
First.x=n-(fs-(n-First.x));
First.flag='N';
}
}
else if(First.flag=='W')
{
First.y-=fs;
if(First.y <= 0)
{
First.y +=fs;
First.y=fs-(First.y-1)+1;
First.flag='E';
}
}
else if(First.flag=='E')
{
First.y+=fs;
if(First.y > n)
{
First.y-=fs;
First.y = n-(fs-(n-First.y));
First.flag='W';
}
}
if(Second.flag=='N')
{
Second.x-=ss;
if(Second.x <= 0)
{
Second.x +=ss;
Second.x=ss-(Second.x-1)+1;
Second.flag='S';
}
}
else if(Second.flag=='S')
{
Second.x+=ss;
if(Second.x > n)
{
Second.x-=ss;
Second.x=n-(ss-(n-Second.x));
Second.flag='N';
}
}
else if(Second.flag=='W')
{
Second.y-=ss;
if(Second.y <= 0)
{
Second.y +=ss;
Second.y=ss-(Second.y-1)+1;
Second.flag='E';
}
}
else if( Second.flag=='E')
{
Second.y+=ss;
if( Second.y > n)
{
Second.y-=ss;
Second.y = n-(ss-(n- Second.y));
Second.flag='W';
}
}
if(First.x == Second.x&&First.y == Second.y)
{
swap(First.flag,Second.flag);
}
else
{
if(i%ft==0)
{
switch(First.flag)
{
case 'N':
First.flag='W';
break;
case 'S':
First.flag='E';
break;
case 'E':
First.flag='N';
break;
case 'W':
First.flag='S';
break;
}
}
if(i%st==0)
{
switch(Second.flag)
{
case 'N':
Second.flag='W';
break;
case 'S':
Second.flag='E';
break;
case 'E':
Second.flag='N';
break;
case 'W':
Second.flag='S';
break;
}
}
}
}
printf("%d %d\n",First.x,First.y);
printf("%d %d\n",Second.x,Second.y);
}
return 0;
}