Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1138954
  • 博文数量: 196
  • 博客积分: 4141
  • 博客等级: 中将
  • 技术积分: 2253
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-21 20:04
文章存档

2019年(31)

2016年(1)

2014年(16)

2011年(8)

2010年(25)

2009年(115)

分类: C/C++

2019-02-20 11:25:35

Mine

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1769    Accepted Submission(s): 513


Problem Description
Have you ever played a game in Windows: Mine?
This game is played on a n*m board, just like the Pic(1)


On the board, Under some grids there are mines (represent by a red flag). There are numbers ‘A(i,j)’ on some grids means there’re A(i,j) mines on the 8 grids which shares a corner or a line with gird(i,j). Some grids are blank means there’re no mines on the 8 grids which shares a corner or a line with them.
At the beginning, all grids are back upward.
In each turn, Player should choose a back upward grid to click.
If he clicks a mine, Game over.
If he clicks a grid with a number on it , the grid turns over.
If he clicks a blank grid, the grid turns over, then check grids in its 8 directions.If the new grid is a blank gird or a grid with a number,it will be clicked too.
So If we click the grid with a red point in Pic(1), grids in the area be encompassed with green line will turn over.
Now Xiemao and Fanglaoshi invent a new mode of playing Mine. They have found out coordinates of all grids with mine in a game. They also find that in a game there is no grid will turn over twice when click 2 different connected components.(In the Pic(2), grid at (1,1) will turn over twice when player clicks (0,0) and (2,2) , test data will not contain these cases).
Then, starting from Xiemao, they click the grid in turns. They both use the best strategy. Both of them will not click any grids with mine, and the one who have no grid to click is the loser.
Now give you the size of board N, M, number of mines K, and positions of every mine Xi,Yi. Please output who will win.
 

Input
Multicase
The first line of the date is an integer T, which is the number of the text cases. (T<=50)
Then T cases follow, each case starts with 3 integers N, M, K indicates the size of the board and the number of mines.Then goes K lines, the ith line with 2 integer Xi,Yi means the position of the ith mine.
1<=N,M<=1000 0<=K<=N*M 0<=Xi  

Output
For each case, first you should print "Case #x: ", where x indicates the case number between 1 and T . Then output the winner of the game, either ”Xiemao” or “Fanglaoshi”. (without quotes)
 

Sample Input
	
		
2 3 3 0 3 3 1 1 1
 

Sample Output
	
	
Case #1: Xiemao Case #2: Fanglaoshi
 

Source


  1. #include <cstdlib>
  2. #include <cmath>
  3. #include <cstdio>
  4. #include <memory.h>
  5. #include <queue>

  6. using namespace std;

  7. int board[1010][1010];
  8. int dir[][2] = {{-1,-1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};

  9. int clickNum(int x, int y, int sizeX, int sizeY) {
  10.     int i;
  11.     int sum;
  12.     int tmpX, tmpY;

  13.     queue<pair<int,int> >q;
  14.     q.push(make_pair(x,y));

  15.     board[x][y] = -2;

  16.     sum = 1;
  17.     while (q.empty() == false) {
  18.         pair<int,int> tmp = q.front();
  19.         q.pop();

  20.         x = tmp.first;
  21.         y = tmp.second;

  22.         for (i = 0; i < 8; ++i) {
  23.             tmpX = x + dir[i][0];
  24.             tmpY = y + dir[i][1];

  25.             if (tmpX < 0 || tmpY < 0 || tmpX >= sizeX || tmpY >= sizeY) {
  26.                 continue;
  27.             }

  28.             if (board[tmpX][tmpY] > 0) {
  29.                 ++sum;
  30.                 board[tmpX][tmpY] = 0 - board[tmpX][tmpY];
  31.                 continue;
  32.             }

  33.             if (board[tmpX][tmpY] == 0) {
  34.                 board[tmpX][tmpY] = -2;
  35.                 q.push(make_pair(tmpX, tmpY));
  36.             }
  37.         }
  38.     }
  39.     
  40.     return sum;
  41. }

  42. int main()
  43. {
  44.     int i, j, k, num;
  45.     int sizeX, sizeY;
  46.     int mineX, mineY;
  47.     int mine;

  48.     int tmpX, tmpY;
  49.     int tmpSum;
  50.     int sum = 0;

  51.     scanf("%d", &num);
  52.     for (i = 0; i < num; ++i) {
  53.         sum = 0;
  54.         memset(board, 0, sizeof(board));
  55.         scanf("%d %d %d", &sizeX, &sizeY, &mine);

  56.         for (j = 0; j < mine; ++j) {
  57.             scanf("%d %d", &mineX, &mineY);
  58.             board[mineX][mineY] = -1;
  59.             for (k = 0; k < 8; ++k) {
  60.                 tmpX = mineX + dir[k][0];
  61.                 tmpY = mineY + dir[k][1];

  62.                 if (tmpX < 0 || tmpY < 0 || tmpX >= sizeX || tmpY >= sizeY) {
  63.                     continue;
  64.                 }

  65.                 if (board[tmpX][tmpY] >= 0) {
  66.                     ++board[tmpX][tmpY];
  67.                 }
  68.             }
  69.         }

  70.         for (j = 0; j < sizeX; ++j) {
  71.             for (k = 0; k < sizeY; ++k) {
  72.                 if (board[j][k] < 0) {
  73.                     continue;
  74.                 }

  75.                 if (board[j][k] == 0) {
  76.                     tmpSum = clickNum(j, k, sizeX, sizeY);
  77.                     if ((tmpSum & 1) == 1) {
  78.                         tmpSum = 1;
  79.                     } else {
  80.                         tmpSum = 2;
  81.                     }
  82.                     sum ^= tmpSum;
  83.                 }
  84.             }
  85.         }

  86.         for (j = 0; j < sizeX; ++j) {
  87.             for (k = 0; k < sizeY; ++k) {
  88.                 if (board[j][k] > 0) {
  89.                     sum ^= 1;
  90.                     board[j][k] = -board[j][k];
  91.                 }
  92.             }
  93.         }

  94.         if (sum == 0) {
  95.             printf("Case #%d: Fanglaoshi\n", i + 1);
  96.         } else {
  97.             printf("Case #%d: Xiemao\n", i + 1);
  98.         }
  99.     }

  100.     return 0;
  101. }

阅读(760) | 评论(0) | 转发(0) |
0

上一篇:Stone

下一篇:虚拟机简述

给主人留下些什么吧!~~