题目传送门
/*
模拟:看懂题意,主要是碰壁后的转向,笔误2次
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
struct Rabbit
{
char c;
int d, s, t;
int x, y;
}r[];
int main(void) //HDOJ 4552 Running Rabbits
{
// freopen ("K.in", "r", stdin);
int n;
while (scanf ("%d", &n) == )
{
if (n == ) break;
getchar ();
for (int i=; i<=; ++i)
{
scanf ("%c %d %d", &r[i].c, &r[i].s, &r[i].t);
if (r[i].c == 'E') r[i].d = ;
else if (r[i].c == 'N') r[i].d = ;
else if (r[i].c == 'W') r[i].d = ;
else r[i].d = ;
getchar ();
}
int k; scanf ("%d", &k);
r[].x = r[].y = ; r[].x = r[].y = n;
for (int i=; i<=k; ++i)
{
for (int j=; j<=; ++j)
{
if (r[j].d == )
{
if (r[j].y + r[j].s > n)
{
r[j].y = * n - (r[j].y + r[j].s);
r[j].d = ;
}
else r[j].y += r[j].s;
}
else if (r[j].d == )
{
if (r[j].x - r[j].s < )
{
r[j].x = + r[j].s - r[j].x;
r[j].d = ;
}
else r[j].x -= r[j].s;
}
else if (r[j].d == )
{
if (r[j].y - r[j].s < )
{
r[j].y = + r[j].s - r[j].y;
r[j].d = ;
}
else r[j].y -= r[j].s;
}
else if (r[j].d == )
{
if (r[j].x + r[j].s > n)
{
r[j].x = * n - (r[j].x + r[j].s);
r[j].d = ;
}
else r[j].x += r[j].s;
}
}
if (r[].x == r[].x && r[].y == r[].y) swap (r[].d, r[].d);
else
{
if (i % r[].t == ) r[].d = (r[].d + ) % ;
if (i % r[].t == ) r[].d = (r[].d + ) % ;
}
}
for (int i=; i<=; ++i) printf ("%d %d\n", r[i].x, r[i].y);
}
return ;
}