Mine

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

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<N 0<=Yi<M
 
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
 
    给出一幅扫雷的地图,告诉你地雷所在位置,两个人轮流点击非炸弹且未显示出来的方格。点击的是空白格子的话会触发八联通格子的点击(如果他们未显示的话),点击的是数字格的话则只会显示点击的这一个格子,不再触发其他的操作。问先手是否处于胜态。
   可以将这个问题划分为一块块的小地图,所有联通的空白格和与他们相邻的数字格是一个独立的游戏,(除去他们之后单独的一个数字格也看作是一个独立的游戏),他们之间不会影响。只要计算出这些子问题的sg值就能推出胜态了。对于独立的一个数字格,sg=1。对于另一种情况,通过枚举可以发现,sg=(子地图中的数字格的数量)%2+1;
 
  一开始dfs一直mle,换成了bfs就好了。还有注意地图是[0][0]开始的,,c。
  

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <stdlib.h>
  6. #include <vector>
  7. #include <set>
  8. #include <queue>
  9. #include <stack>
  10. using namespace std;
  11. #define mp make_pair
  12. #define pii pair<int,int>
  13. int n,m,tot;
  14. int e[][];
  15. bool vis[][];
  16. int fx[][]={-,,,,,-,,,-,-,-,,,-,,};
  17. void bfs(int x,int y){
  18. queue<pair<int,int> >q;
  19. q.push(mp(x,y));
  20. while(!q.empty()){
  21. pii tmp=q.front();
  22. q.pop();
  23. if(vis[tmp.first][tmp.second]) continue;
  24. vis[tmp.first][tmp.second]=;
  25. if(e[tmp.first][tmp.second]==) {tot++;continue;}
  26. for(int i=;i<;++i){
  27. int dx=tmp.first+fx[i][];
  28. int dy=tmp.second+fx[i][];
  29. if(dx<||dy<||dx>n||dy>m||vis[dx][dy]) continue;
  30. q.push(mp(dx,dy));
  31. }
  32. }
  33. }
  34. int main(){
  35. int t,i,j,k,cas=;
  36. cin>>t;
  37. while(t--){
  38. memset(vis,,sizeof(vis));
  39. memset(e,,sizeof(e));
  40. cin>>n>>m>>k;
  41. int x,y;
  42. while(k--){
  43. scanf("%d%d",&x,&y);
  44. x++;
  45. y++;
  46. vis[x][y]=;
  47. e[x][y]=;
  48. for(i=;i<;++i){
  49. int dx=x+fx[i][];
  50. int dy=y+fx[i][];
  51. if(dx>&&dy>&&dx<=n&&dy<=m&&vis[dx][dy]==) e[dx][dy]=;
  52. }
  53. }
  54. int sg=;
  55. for(i=;i<=n;++i){
  56. for(j=;j<=m;++j){
  57. if(vis[i][j]||e[i][j]==) continue;
  58. tot=;
  59. bfs(i,j);
  60. sg^=(tot%+);
  61. }
  62. }
  63. for(i=;i<=n;++i)
  64. for(j=;j<=m;++j)
  65. if(!vis[i][j]&&e[i][j]==) sg^=;
  66. printf("Case #%d: ",++cas);
  67. sg?puts("Xiemao"):puts("Fanglaoshi");
  68. }
  69. return ;
  70. }
  

hdu-4678-sg的更多相关文章

  1. hdu 4678 Mine

    HDU 4678 把点开空地时会打开的一大片区域看成一块,题目中说到,在一盘游戏 中,一个格子不可能被翻开两次,说明任意两块空地不会包含相同的格子. 那么就可以看成一个组合游戏. 当空地旁边没连任何数 ...

  2. hdu 5724 SG+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  3. HDU 4678 Mine SG博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=4678 自己太蠢...没学SG...还是浩神指点我SG精髓以后才A的这题...(第一题SG 这里子游戏之间没有影响 ...

  4. hdu 2147 SG函数打表(手写也可以) 找规律

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total ...

  5. HDU 1848 SG函数博弈

    Fibonacci again and again Problem Description   任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...

  6. hdu 3032 sg打表找规律 *

    有n堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) ,也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 打表代码: #include ...

  7. HDU 1536 sg函数

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. hdu 4678 Mine 博弈论

    这是一题简单的博弈论!! 所有的空白+边界的数字(个数为n)为一堆,容易推出其SG函数值为n%2+1: 其他所有的数字(个数为m)的SG值为m%2. 再就是用dfs将空白部分搜一下即可!(注意细节) ...

  9. hdu 1536 SG函数模板题

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  10. hdu 4678

    HDU 4768: Flyer 题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2...  && A+k*C <= B).题目保证 ...

随机推荐

  1. 你真的了解微服务架构吗?听听八年阿里架构师怎样讲述Dubbo和Spring Cloud微服务架构

    微服务架构是互联网很热门的话题,是互联网技术发展的必然结果.它提倡将单一应用程序划分成一组小的服务,服务之间互相协调.互相配合,为用户提供最终价值.虽然微服务架构没有公认的技术标准和规范或者草案,但业 ...

  2. OpenCV Using Python——基于SURF特征提取和金字塔LK光流法的单目视觉三维重建 (光流、场景流)

    https://blog.csdn.net/shadow_guo/article/details/44312691 基于SURF特征提取和金字塔LK光流法的单目视觉三维重建 1. 单目视觉三维重建问题 ...

  3. 1、初始Java应用程序

    Java Application程序,也称为Java应用程序,是可独立的应用程序.该类程序以main()方法作为入口,由独立的Java解释器加载执行. 下面的列子是一个简单的Java应用程序. imp ...

  4. python3 isinstance()判断元素是否是字符串、int型、float型

    python3 isinstance()判断元素是否是字符串.int型.float型 isinstance是Python中的一个内建函数 语法: isinstance(object, classinf ...

  5. Python3.x(windows系统)安装libxml2库

    Python3.x(windows系统)安装libxml2库 cmd安装命令: pip install lxml 执行结果: 再执行命令: pip install virtualenv 执行结果:

  6. Win10 Ubuntu 双系统 卸载 Ubuntu

    Win10 Ubuntu 双系统 卸载 Ubuntu 其实卸载 Ubuntu 系统很简单,进 win10 系统之后,磁盘管理,格式化 Ubuntu 的磁盘就可以了. 但是最费劲的是什么呢? 就是格式化 ...

  7. 关于即来即停app的功能

    Asmallpark软件接口文档说明 编码均采用UTF-8格式传输全部为http,POST请求状态码:200  操作成功    100  服务器异常,稍后再试  404  请求非法  402  数据库 ...

  8. LTE-A 载波聚合(Carrier Aggregation)介绍【转】

    本文转自:https://blog.csdn.net/txgc1009/article/details/46467255 载波聚合(Carrier Aggregation) 首先介绍几个基本概念 Pr ...

  9. 【TCP/IP详解 卷一:协议】第十七章 TCP:传输控制协议

    本章作为TCP的入门章节,简单的概述了一些TCP的知识,和TCP数据报的首部格式. TCP 最重要的特性:reliable. 17.1 引言 本章介绍的是 TCP为应用层提供的服务. 17.2 TCP ...

  10. FPGA 概述

    概述 verilog HDL Verilog HDL基本结构 1 Verilog HDL程序是由模块构成的.每个模块嵌套在module和endmodule声明语句中. 2 每个Verilog HDL源 ...