1219.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 27 行

CPP
27
字号
/*  This Code is Submitted by wywcgs for Problem 1219 on 2006-01-09 at 22:47:43 */ 
#include <cstdio>

int main()
{
	int x, y, dx, dy, n, s;

	while(scanf("%d %d %d %d %d", &s, &x, &y, &dx, &dy) != EOF && dx != 0) {
		int ox = x % s, oy = y % s, rn = 0;
		for(n = 0; true; n++) {
			if(x%s != 0 && y%s != 0 && (x/s+y/s)%2 == 1) {
				printf("After %d jumps the flea lands at (%d, %d).\n", n, x, y);
				break;
			}
			x += dx, y += dy;
			if(x%s == ox && y%s == oy) {
				if(++rn == 2) {
					printf("The flea cannot escape from black squares.\n");
					break;
				}
			}
		}
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?