zoukankan      html  css  js  c++  java
  • hdu4678Mine

    http://acm.hdu.edu.cn/showproblem.php?pid=4678

    之前写了一并差集找连通块 貌似不对 比赛时写的dfs爆栈了 只好用bfs了

    单独数字块  为1

    空白+数字块 数字数%2+1

    异或

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<stdlib.h>
     5 #include<algorithm>
     6 #include<queue>
     7 using namespace std;
     8 #define N 1010
     9 int dis[8][2] = {1,0,-1,0,0,1,0,-1,1,1,1,-1,-1,1,-1,-1};
    10 int n,m,k;
    11 int vis[N][N],o[N][N],f[N][N];
    12 struct node
    13 {
    14     int x,y;
    15 };
    16 int bfs(int x,int y)
    17 {
    18     queue<node>q;
    19     struct node st,sd;
    20     int num = 0,i;
    21     st.x = x;
    22     st.y = y;
    23     vis[x][y] = 1;
    24     q.push(st);
    25     while(!q.empty())
    26     {
    27         sd = q.front();
    28         int tx = sd.x;
    29         int ty = sd.y;
    30         q.pop();
    31         for(i = 0 ;i < 8 ; i++)
    32         {
    33             int dx = tx+dis[i][0];
    34             int dy = ty+dis[i][1];
    35             if(dx>=0&&dx<n&&dy>=0&&dy<m&&!vis[dx][dy])
    36             {
    37                 vis[dx][dy] = 1;
    38                 if(!f[dx][dy]&&o[dx][dy])
    39                 num++;
    40                 st.x = dx;
    41                 st.y = dy;
    42                 if(!f[dx][dy]&&!o[dx][dy])
    43                 q.push(st);
    44             }
    45         }
    46     }
    47     if(num%2==0)
    48     return 1;
    49     return 2;
    50 }
    51 int main()
    52 {
    53     int i,j,t,kk=0;
    54     scanf("%d",&t);
    55     while(t--)
    56     {
    57         kk++;
    58         scanf("%d%d%d",&n,&m,&k);
    59         for(i = 0 ; i <= n ; i++)
    60             for(j = 0 ; j  <= m ; j++)
    61             {
    62                 f[i][j] = 0;
    63                 o[i][j] = 0;
    64                 vis[i][j] = 0;
    65             }
    66         while(k--)
    67         {
    68             int x,y;
    69             scanf("%d%d",&x,&y);
    70             f[x][y] = 1;
    71             for(i = 0 ; i < 8 ; i++)
    72             {
    73                 int tx = x+dis[i][0];
    74                 int ty = y+dis[i][1];
    75                 if(tx>=0&&tx<n&&ty>=0&&ty<m)
    76                 o[tx][ty] = 1;
    77             }
    78         }
    79         int ans=0;
    80         for(i = 0 ; i < n ; i++)
    81             for(j = 0 ; j < m ; j++)
    82             if(!f[i][j]&&!vis[i][j]&&o[i][j]==0)
    83             {
    84                 int w = bfs(i,j);
    85                 ans ^= w;
    86             }
    87         for(i = 0 ; i < n ; i++)
    88             for(j = 0 ; j < m ; j++)
    89             if(!f[i][j]&&!vis[i][j]&&o[i][j])
    90             ans ^= 1;
    91         printf("Case #%d: ",kk);
    92         if(ans==0)
    93         printf("Fanglaoshi
    ");
    94         else
    95         printf("Xiemao
    ");
    96     }
    97     return 0;
    98 }
    View Code
  • 相关阅读:
    Software_programming_automation_selenium
    Software_programming_EnterpriseArch_ServiceWithSingleTonFactory
    web-bootstrap-button
    Software--C#--grammer_Delegate--Event
    Software_C#_grammer_Deletegate--Strategy
    Software--BigData--StreamingData
    线程死锁和递归锁
    同步锁Lock(互斥锁)
    GIL计算python 2 和 python 3 计算密集型
    什么是python的全局解释锁(GIL)
  • 原文地址:https://www.cnblogs.com/shangyu/p/3260872.html
Copyright © 2011-2022 走看看