• HDU 4678 Mine


    Mine

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)

    Total Submission(s): 855    Accepted Submission(s): 259

    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
     

    多校第八场的一道博弈题,说是在一个扫雷的格子中,两个人轮流点击(它们事先都知道雷的位置),转到哪一个人的时候它只能点雷,那么这个人就输了、

    当时想的作法很诡异,第八场比赛本来已经抱着被AK的心态了,结果我胡乱推导的过程中发现了一丝规律,于是抱着签到(一场比赛总不能一次提交都没有吧,囧)肯必WA的心态交了一发,结果居然过了。。。

    当然RE了一次,把DFS的递归调用改成了手写的栈才过了这个题,代码很丑思路也很糟,就不解释了,过几天参考解题报告想出更好的解法了再来更新

      1 #include<iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 
      5 using namespace std;
      6 
      7 typedef struct node
      8 {
      9     int x;
     10     int y;
     11 } NODE;
     12 
     13 int n,m,k;
     14 int g[1050][1050],gt[1050][1050];
     15 NODE Stack[1000000];
     16 
     17 int main()
     18 {
     19     int t;
     20 
     21     scanf("%d",&t);
     22 
     23     for(int kase=1;kase<=t;kase++)
     24     {
     25         scanf("%d %d %d",&n,&m,&k);
     26         memset(g,0,sizeof(g));
     27         memset(gt,0,sizeof(gt));
     28         for(int i=0;i<=n+1;i++)
     29             g[i][0]=g[i][m+1]=-2;
     30         for(int j=0;j<=m+1;j++)
     31             g[0][j]=g[n+1][j]=-2;
     32         for(int i=1;i<=k;i++)
     33         {
     34             int x,y;
     35             scanf("%d %d",&x,&y);
     36             g[x+1][y+1]=-1;
     37         }
     38         if(k==0)
     39         {
     40             printf("Case #%d: Xiemao
    ",kase);
     41             continue;
     42         }
     43         for(int i=1;i<=n;i++)
     44             for(int j=1;j<=m;j++)
     45             {
     46                 if(g[i][j]==-1)
     47                 {
     48                     if(g[i-1][j-1]>=0)
     49                         g[i-1][j-1]++;
     50                     if(g[i-1][j]>=0)
     51                         g[i-1][j]++;
     52                     if(g[i-1][j+1]>=0)
     53                         g[i-1][j+1]++;
     54                     if(g[i][j-1]>=0)
     55                         g[i][j-1]++;
     56                     if(g[i][j+1]>=0)
     57                         g[i][j+1]++;
     58                     if(g[i+1][j-1]>=0)
     59                         g[i+1][j-1]++;
     60                     if(g[i+1][j]>=0)
     61                         g[i+1][j]++;
     62                     if(g[i+1][j+1]>=0)
     63                         g[i+1][j+1]++;
     64                 }
     65             }
     66         int boundary=0,mast=0;
     67         for(int i=1;i<=n;i++)
     68             for(int j=1;j<=m;j++)
     69             {
     70                 if(g[i][j]!=0&&g[i][j]!=-1)
     71                     if(g[i-1][j-1]==0||g[i-1][j]==0||g[i-1][j+1]==0||g[i][j-1]==0||g[i][j+1]==0||g[i+1][j-1]==0||g[i+1][j]==0||g[i+1][j+1]==0)
     72                         boundary++;
     73                     else
     74                         mast++;
     75             }
     76         for(int i=0;i<=n+1;i++)
     77             for(int j=0;j<=m+1;j++)
     78                 gt[i][j]=(g[i][j]==0?0:1);
     79         int blocks=0;
     80         for(int i=1;i<=n;i++)
     81             for(int j=1;j<=m;j++)
     82             {
     83                 if(gt[i][j]==0)
     84                 {
     85                     blocks++;
     86                     g[i][j]=1;
     87                     int l=0,r=0;
     88                     NODE temp;
     89                     temp.x=i;
     90                     temp.y=j;
     91                     Stack[r++]=temp;
     92                     while(l<r)
     93                     {
     94                         if(gt[Stack[l].x-1][Stack[l].y]==0)
     95                         {
     96                             gt[Stack[l].x-1][Stack[l].y]=1;
     97                             temp.x=Stack[l].x-1;
     98                             temp.y=Stack[l].y;
     99                             Stack[r++]=temp;
    100                         }
    101                         if(gt[Stack[l].x+1][Stack[l].y]==0)
    102                         {
    103                             gt[Stack[l].x+1][Stack[l].y]=1;
    104                             temp.x=Stack[l].x+1;
    105                             temp.y=Stack[l].y;
    106                             Stack[r++]=temp;
    107                         }
    108                         if(gt[Stack[l].x][Stack[l].y-1]==0)
    109                         {
    110                             gt[Stack[l].x][Stack[l].y-1]=1;
    111                             temp.x=Stack[l].x;
    112                             temp.y=Stack[l].y-1;
    113                             Stack[r++]=temp;
    114                         }
    115                         if(gt[Stack[l].x][Stack[l].y+1]==0)
    116                         {
    117                             gt[Stack[l].x][Stack[l].y+1]=1;
    118                             temp.x=Stack[l].x;
    119                             temp.y=Stack[l].y+1;
    120                             Stack[r++]=temp;
    121                         }
    122                         l++;
    123                     }
    124                 }
    125             }
    126         if(mast%2==1)
    127         {
    128             if(blocks%2==1)
    129             {
    130                 if(boundary%2==0)
    131                     printf("Case #%d: Fanglaoshi
    ",kase);
    132                 else
    133                     printf("Case #%d: Xiemao
    ",kase);
    134             }
    135             else
    136                 printf("Case #%d: Xiemao
    ",kase);
    137         }
    138         else
    139         {
    140             if(blocks%2==1)
    141                 printf("Case #%d: Xiemao
    ",kase);
    142             else
    143             {
    144                 if(boundary%2==0)
    145                     printf("Case #%d: Fanglaoshi
    ",kase);
    146                 else
    147                     printf("Case #%d: Xiemao
    ",kase);
    148             }
    149         }
    150     }
    151 
    152     return 0;
    153 }
    [C++]
  • 相关阅读:
    react获取ref的几种形式
    vue与react的小区别
    vue当中计算属性重新计算依赖关系
    移动端常见问题
    WX小程序--开发中相关问题记录
    ECMAScript6 入门 Set 和Map结构
    ECMAScript6 入门 Class 的基本语法与继承
    ECMAScript6 入门 Generator
    ECMAScript6 入门 Promise
    ECMAScript6 入门 Symbol
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3270870.html
Copyright © 2020-2023  润新知