格子游戏 //假的

【问题描述】
  Alice和Bob玩了一个古老的游戏:首先画一个n * n的点阵(下图n = 3)   接着,他们两个轮流在相邻的点之间画上红边和蓝边:
 
    直到围成一个封闭的圈(面积不必为1)为止,“封圈”的那个人就是赢家。因为棋盘实在是太大了(n <= 200),他们的游戏实在是太长了!他们甚至在游戏中都不知道谁赢得了游戏。于是请你写一个程序,帮助他们计算他们是否结束了游戏?
【输入格式】
  输入数据第一行为两个整数n和m。m表示一共画了m条线。以后m行,每行首先有两个数字(x, y),代表了画线的起点坐标,接着用空格隔开一个字符,假如字符是"D ",则是向下连一条边,如果是"R "就是向右连一条边。输入数据不会有重复的边且保证正确。
【输出格式】
  输出一行:在第几步的时候结束。假如m步之后也没有结束,则输出一行“draw”。
【输入样例】
  3 5
  1 1 D
  1 1 R
  1 2 D
  2 1 R
  2 2 D
【输出样例】
  4
 1 #include<iostream>
 2 using namespace std;
 3 #include<cstdio>
 4 #include<cstring>
 5 int father[1000008];
 6 int node[10001][10001];
 7 
 8 
 9 /*int find(int x)
10 {
11     if(father[x]!=x)father[x]=find(father[x]);
12     else return x;
13 }*/
14 int nfather[1000001];
15 int main()
16 {
17     int N,M;
18     scanf("%d%d",&N,&M);
19     for(int i=1;i<=N;i++)
20     for(int j=1;j<=N;j++)
21     {
22         node[i][j]=i*10+j;
23         father[i*10+j]=i*10+j;
24     }
25     for(int i=1;i<=M;i++)
26     {
27         int a,b;char c;
28         cin>>a>>b>>c;
29         if(c=='R')
30         {
31             b=b+1;
32             father[node[a][b]]=father[node[a][b-1]];
33         }
34         if(c=='D')
35         {
36             a=a+1;
37             father[node[a][b]]=father[node[a-1][b]];
38         }
39         nfather[node[a][b]]++;
40         if(nfather[node[a][b]]>=2&&father[node[a-1][b]]==father[node[a][b-1]])
41         {
42             printf("%d",i);
43             return 0;
44         }    
45     }
46     return 0;
47 }
 
 
原文地址:https://www.cnblogs.com/sssy/p/6699824.html