結果
| 問題 | 
                            No.208 王将
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-05-23 19:35:58 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,458 bytes | 
| コンパイル時間 | 368 ms | 
| コンパイル使用メモリ | 54,588 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-06 06:22:32 | 
| 合計ジャッジ時間 | 1,214 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 1 | 
| other | AC * 4 WA * 19 | 
ソースコード
#include <stdio.h>
#include <iostream>
using namespace std;
bool safe(int, int, int, int);
void print();
struct Point {
	int x;
	int y;
};
Point now = { 0, 0 };
Point goal = { 10, 1 };
Point obst = { 1, 0 };
int map[40][40] = {{0}};
int main(int argc, char *argv[]) {
	map[20][20] = 7;
	map[obst.x + 20][obst.y + 20] = 4;
	map[goal.x + 20][goal.y + 20] = 9;
	int dirx;
	int diry;
	int flag;
	int cnt = 0;
	while (1) {
		dirx = goal.x - now.x; //dirx>0 で右に進むべき
		diry = goal.y - now.y; //diry>0 で左に進むべき
		flag = (abs(dirx) > abs(diry));
		if (dirx > 0) {
			if (diry > 0) { // 右上
				if (safe(now.x, now.y, dirx, diry)) {
					now.x++;
					now.y++;
				}
				else {
					now.x += flag;
					now.y += !flag;
				}
			}
			else if (diry < 0) { // 右下
				if (safe(now.x, now.y, dirx, diry)) {
					now.x++;
					now.y--;
				}
				else {
					now.x += flag;
					now.y += !flag;
				}
			}
			else if (diry == 0) { // 右
				now.x++;
			}
		}
		else if (dirx < 0) {
			if (diry > 0) { // 左上
				if (safe(now.x, now.y, dirx, diry)) {
					now.x--;
					now.y++;
				}
				else {
					now.x += flag;
					now.y += !flag;
				}
			}
			else if (diry < 0) { // 左下
				if (safe(now.x, now.y, dirx, diry)) {
					now.x--;
					now.y--;
				}
				else {
					now.x += flag;
					now.y += !flag;
				}
			}
			else if (diry == 0) { // 左
				now.x--;
			}
		}
		else if (dirx == 0) {
			if (diry > 0) { // 上
				now.y++;
			}
			else if (diry < 0) { // 下
				now.y--;
			}
			else if (diry == 0) { // 到着
				map[now.x + 20][now.y + 20] = 9;
				break;
			}
		}
		map[now.x + 20][now.y + 20] = 1;
		cnt++;
	}
	print();
	printf("%d\n", cnt);
	// scanf("%d", &cnt);
	return 0;
}
bool safe(int nowx, int nowy, int dirx, int diry) {
	bool toRight = (dirx > 0);
	bool toLeft = !toRight;
	bool toUp = (diry > 0);
	bool toBottom = !toUp;
	if (toRight && toUp) {
		return !((now.x + 2 == obst.x) && (now.y + 2 == obst.y));
	}
	else if (toRight && toBottom) {
		return !((now.x + 2 == obst.x) && (now.y - 2 == obst.y));
	}
	else if (toLeft && toUp) {
		return !((now.x - 2 == obst.x) && (now.y + 2 == obst.y));
	}
	else {
		return !((now.x - 2 == obst.x) && (now.y - 2 == obst.y));
	}
}
void print() {
	//for (int i = 0; i < 40; i++) {
	//	for (int j = 0; j < 40; j++) {
	//		if (map[40-i][j] != 0) {
	//			printf("%d", map[40-i][j]);
	//		}
	//		else {
	//			printf(" ");
	//		}
	//			
	//	}
	//	printf("\n");
	//}
}