zoukankan      html  css  js  c++  java
  • HDU 4678 Mine(博弈)

    Mine

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

    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
     
    Recommend
    zhuyuanchen520
     1 博弈题;用SG值做:
     2 连通的空白块和相连的数字块是一起的,一个单独的数字块是一类。
     3 单独一个的数组块,SG是1.
     4 空白块+若干个数字块,数字块个数为n的话,SG是n%2 + 1(自己手动算几个就知道了!!)
     5 
     6 做法:地雷标记为2;数字标记为1;空白的为0;
     7 
     8 然后开始扫一遍,当遇到空白的就dfs空白的一块并把它标记掉(可以标记为2)。如此就把含空白的快分离出来了!
     9 
    10 最后只要数一下含1的个数即可;
    11 
    12 
    13 #pragma comment(linker, "/STACK:102400000,102400000")
    14 #include<cstdio>
    15 #include<cstring>
    16 #include<algorithm>
    17 using namespace std;
    18 
    19 int n,m,lei,ans,num;
    20 int maz[1110][1110];
    21 
    22 void dfs(int x,int y)
    23 {
    24     if(x<1||x>n||y<1||y>m) return ;
    25     if(maz[x][y]==0)
    26     {
    27         maz[x][y]=2;
    28         dfs(x,y-1);
    29         dfs(x,y+1);
    30         dfs(x-1,y-1);
    31         dfs(x-1,y);
    32         dfs(x-1,y+1);
    33         dfs(x+1,y-1);
    34         dfs(x+1,y);
    35         dfs(x+1,y+1);
    36     }
    37     else if(maz[x][y]==1)
    38     {
    39         num++;
    40         maz[x][y]=2;
    41     }
    42 }
    43 
    44 int main()
    45 {
    46     int t,cas,i,j,tx,ty,res;
    47     scanf("%d",&t);
    48     cas=1;
    49     while(t--)
    50     {
    51         memset(maz,0,sizeof(maz));
    52         scanf("%d%d%d",&n,&m,&lei);
    53         for(i=1;i<=lei;i++)
    54         {
    55             scanf("%d%d",&tx,&ty);
    56             tx++;
    57             ty++;
    58             maz[tx][ty]=2;
    59             if(maz[tx][ty-1]==0) maz[tx][ty-1]=1;
    60             if(maz[tx][ty+1]==0) maz[tx][ty+1]=1;
    61             if(maz[tx+1][ty-1]==0) maz[tx+1][ty-1]=1;
    62             if(maz[tx+1][ty]==0) maz[tx+1][ty]=1;
    63             if(maz[tx+1][ty+1]==0) maz[tx+1][ty+1]=1;
    64             if(maz[tx-1][ty-1]==0) maz[tx-1][ty-1]=1;
    65             if(maz[tx-1][ty]==0) maz[tx-1][ty]=1;
    66             if(maz[tx-1][ty+1]==0) maz[tx-1][ty+1]=1;
    67         }
    68         ans=0;
    69         for(i=1;i<=n;i++)
    70         {
    71             for(j=1;j<=m;j++)
    72             {
    73                 if(!maz[i][j])//遇见空格,就开始dfs这一块!!
    74                 {
    75                     num=1;//num为这一块总共有几个格子(attention!连在一起的所有的空白格子算一大格!)
    76                     dfs(i,j);
    77                     if(num%2==1) ans^=1;
    78                     else ans^=2;
    79                 }
    80             }
    81         }
    82         res=0;
    83         for(i=1;i<=n;i++)
    84         {
    85             for(j=1;j<=m;j++)
    86             {
    87                 if(maz[i][j]==1) res++;
    88             }
    89         }
    90         if(res%2==1) ans^=1;
    91         if(ans==0) printf("Case #%d: Fanglaoshi
    ",cas++);
    92         else printf("Case #%d: Xiemao
    ",cas++);
    93     }
    94     return 0;
    95 }
    View Code
  • 相关阅读:
    高性能javascript学习笔记系列(1) -js的加载和执行
    拖放 js
    js 内存小记
    原生方法系列 3(查缺补漏 不断更新)
    mongodb系列3 mongo mongoskin 连接以及连接数的问题进阶
    自定义浏览器alert ,抛弃掉死板的蓝框 自定义风格提示框。jquey ui bootstrap 实现自定义 alert confirm prompt ,by大崔
    CSS颜色代码大全
    WCF简单应用总结 by Jimmyzzc
    时间戳转换
    Ajax+MVC异常错误返回
  • 原文地址:https://www.cnblogs.com/skykill/p/3262740.html
Copyright © 2011-2022 走看看