hdu 4452 Running Rabbits

一道简单的模拟题,代码写得太水,卡了很长时间,碰上我这样的坑爹队友也是不幸啊

#include <bits/stdc++.h>

using namespace std;

int mov[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
map <char, int> dir;
int n;

int check(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= n;
}

int main() {

	dir['N'] = 0;
	dir['W'] = 1;
	dir['S'] = 2;
	dir['E'] = 3;

	while(~scanf("%d", &n) && n) {
		char dir1[2], dir2[2];
	   	int	v1, t1, v2, t2;
		scanf("%s%d%d", dir1, &v1, &t1);
		scanf("%s%d%d", dir2, &v2, &t2);
		int k;
		scanf("%d", &k);
		int x1, y1, x2, y2;
		int ndir1, ndir2;
		ndir1 = dir[dir1[0]]; ndir2 = dir[dir2[0]];
		x1 = y1 = 1;
		x2 = y2 = n;

		for (int j = 1; j <= k; j++) {
			int tx1 = x1, ty1 = y1;
			for (int i = 0; i < v1; i++) {
				tx1 = tx1 + mov[ndir1][0];
				ty1 = ty1 + mov[ndir1][1];
				if (!check(tx1, ty1)) {
					tx1 = tx1 - mov[ndir1][0];
					ty1 = ty1 - mov[ndir1][1];
					ndir1 = (ndir1 + 2) % 4;
					i--;
				}
			}
			x1 = tx1; y1 = ty1;

			int tx2 = x2, ty2 = y2;
			for (int i = 0; i < v2; i++) {
				tx2 = tx2 + mov[ndir2][0];
				ty2 = ty2 + mov[ndir2][1];
				if (!check(tx2, ty2)) {
					tx2 = tx2 - mov[ndir2][0];
					ty2 = ty2 - mov[ndir2][1];
					ndir2 = (ndir2 + 2) % 4;
					i--;
				}
			}
			x2 = tx2; y2 = ty2;

			if (x1 == x2 && y1 == y2) {
				swap(ndir1, ndir2);
			}	
			else {
				if (j % t1 == 0) {
					ndir1 = (ndir1 + 1) % 4;
				}
				if (j % t2 == 0) {
					ndir2 = (ndir2 + 1) % 4;
				}
			}
		}
		printf("%d %d\n", x1, y1);
		printf("%d %d\n", x2, y2);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值