/*
模拟题,做的比较有感觉
以前不太擅长做模拟题,因为总是模拟中找公式,所以往往会复杂很多
①处,原来想直接用公式求出下一步坐标,结果太麻烦。
后来直接用一个for()循环实现,简单很多
*/
#include <cstdio>
int N;
void fgo(int &d, int &x, int &y, int s)
{
int i;
switch(d)
{
case 1:
case 3:
for(i = 0; i < s; ++ i)//①
{
y += (d == 1 ? -1 : 1);
if(y < 1)
{
y = 2;
d = 3;
}
else if(y > N)
{
y = N - 1;
d = 1;
}
}
break;
case 0:
case 2:
for(i = 0; i < s; ++ i)
{
x += (d == 0 ? -1 : 1);
if(x < 1)
{
x = 2;
d = 2;
}
else if(x > N)
{
x = N - 1;
d = 0;
}
}
break;
}
}
void convert(char c, int &d)
{
switch(c)
{
case 'N':
d = 0;
break;
case 'W':
d = 1;
break;
case 'S':
d = 2;
break;
case 'E':
d = 3;
break;
}
}
int main()
{
while(scanf("%d", &N) != EOF)
{
if(!N) break;
char c1[5], c2[5];
int s1, t1, s2, t2;
scanf("%s%d%d%s%d%d", c1, &s1, &t1, c2, &s2, &t2);
int k;
scanf("%d", &k);
int i;
int x1, y1, x2, y2;
x1 = y1 = 1;
x2 = y2 = N;
int d1, d2;
convert(c1[0], d1);
convert(c2[0], d2);
for(i = 1; i <= k; ++ i)
{
fgo(d1, x1, y1, s1);
fgo(d2, x2, y2, s2);
if(x1 == x2 && y1 == y2)
{
int temp = d1;
d1 = d2;
d2 = temp;
continue;
}
if(i % t1 == 0)
d1 = (d1 + 1) % 4;
if(i % t2 == 0)
d2 = (d2 + 1) % 4;
}
printf("%d %d\n%d %d\n", x1, y1, x2, y2);
}
return 0;
}
HDU Running Rabbits(模拟)
最新推荐文章于 2020-07-30 21:09:45 发布