题意:给你一个图,包含空格 。 和墙* , 你现在要在空格处放置1x2的格子使得空白处全部填满,问你是否是 (有解或者多个解) 还是(只有一个解).

解题思路:这个题图太大了,显然不能用DLX或者状压dp,应该怎么样能,我们知道 如果一个空白边上三面都是墙或者已经填被填上了,那这个空白只有一种填法,

然后根据这个性质去进行搜索就能个得到是否只有一个解了。

解题代码:

  1 // File Name: b.cpp
  2 // Author: darkdream
  3 // Created Time: 2015年02月18日 星期三 01时06分26秒
  4 
  5 #include<vector>
  6 #include<list>
  7 #include<map>
  8 #include<set>
  9 #include<deque>
 10 #include<stack>
 11 #include<bitset>
 12 #include<algorithm>
 13 #include<functional>
 14 #include<numeric>
 15 #include<utility>
 16 #include<sstream>
 17 #include<iostream>
 18 #include<iomanip>
 19 #include<cstdio>
 20 #include<cmath>
 21 #include<cstdlib>
 22 #include<cstring>
 23 #include<ctime>
 24 #include<queue>
 25 #define LL long long
 26 
 27 using namespace std;
 28 char str[2004][2004];
 29 struct node{
 30   int x, y ; 
 31   node()
 32   {}
 33   node(int _x,int _y)
 34   {
 35      x= _x; 
 36      y= _y;
 37   }
 38 };
 39 queue <node> q3;
 40 void cheack(int x, int y)
 41 {
 42    if(str[x][y] == '.' )
 43    {
 44       int sum = 0 ; 
 45       if(str[x][y+1] == '.')
 46        sum ++;
 47       if(str[x][y-1] == '.')
 48        sum ++;
 49       if(str[x+1][y] == '.')
 50        sum ++;
 51       if(str[x-1][y] == '.')
 52        sum ++;
 53       if(sum == 1) 
 54           q3.push(node(x,y));
 55    }
 56 }
 57 void cheackaround(int x, int y)
 58 {
 59    cheack(x,y-1);
 60    cheack(x,y+1);
 61    cheack(x+1,y);
 62    cheack(x-1,y);
 63 }
 64 void solve()
 65 {
 66     while(q3.size() != 0 )
 67     {
 68       node tmp = q3.front();
 69       q3.pop();
 70       int x = tmp.x;
 71       int y = tmp.y;
 72       if(str[x][y+1] == '.')
 73       {
 74          str[x][y] = '<';
 75          str[x][y+1] = '>';
 76          cheackaround(x,y+1);
 77       }
 78       if(str[x][y-1] == '.')
 79       {
 80         str[x][y] = '>';
 81         str[x][y-1] = '<';
 82         cheackaround(x,y-1);
 83       }
 84       if(str[x+1][y] == '.')
 85       {
 86         str[x][y] = '^';
 87         str[x+1][y] = 'v';
 88         cheackaround(x+1,y);
 89       }
 90       if(str[x-1][y] == '.')
 91       {
 92         str[x][y] = 'v';
 93         str[x-1][y] = '^';
 94         cheackaround(x-1,y);
 95       }
 96     }
 97 }
 98 int main(){
 99    int n , m; 
100    scanf("%d %d",&n,&m);
101    for(int i = 1;i <= n;i ++)
102    {
103      scanf("%s",&str[i][1]);
104    }
105    for(int i = 1;i <= n;i ++)
106        for(int j = 1;j <= m;j ++)
107        {
108           cheack(i,j);    
109        }
110    solve();
111    for(int i = 1;i <= n;i ++)
112        for(int j= 1;j <= m; j ++)
113        {
114          if(str[i][j] == '.')
115          {
116            printf("Not unique\n");
117            return 0 ; 
118          }
119        }
120    for(int i = 1;i <= n;i ++)
121        printf("%s\n",&str[i][1]);
122 
123 return 0;
124 }
View Code

 

posted on 2015-03-27 21:45  dark_dream  阅读(138)  评论(0编辑  收藏  举报