题目链接:http://codeforces.com/problemset/problem/516/B

一个n*m的方格,'*'不能填。给你很多个1*2的尖括号,问你是否能用唯一填法填满方格。

类似topsort,'.'与上下左右的'.',的相连。从度为1的点作为突破口。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 2e3 + ;
int n, m, tx[] = {-, , , }, ty[] = {, -, , };
char str[N][N];
int du[N*N];
vector <int> G[N*N];
inline bool judge(int x, int y) {
if(x >= && x < n && y >= && y < m && str[x][y] == '.')
return true;
return false;
}
inline void get(int x, int y) {
for(int i = ; i < ; ++i) {
int xx = x + tx[i], yy = y + ty[i];
if(judge(xx, yy)) {
G[x*m + y].push_back(xx*m + yy);
du[x*m + y]++;
}
}
}
inline void change(int x, int y) {
if(m == ) {
if(x < y) {
str[x][] = '^';
str[y][] = 'v';
} else {
str[x][] = 'v';
str[y][] = '^';
}
} else {
if(x - y == -m) {
str[x/m][x%m] = '^';
str[y/m][y%m] = 'v';
} else if(x - y == m) {
str[x/m][x%m] = 'v';
str[y/m][y%m] = '^';
} else if(x - y == -) {
str[x/m][x%m] = '<';
str[y/m][y%m] = '>';
} else {
str[x/m][x%m] = '>';
str[y/m][y%m] = '<';
}
}
} int main()
{
int cnt = , op = ;
scanf("%d %d", &n, &m);
for(int i = ; i < n; ++i) {
scanf("%s", str[i]);
}
for(int i = ; i < n; ++i) {
for(int j = ; j < m; ++j) {
if(judge(i, j)) {
get(i, j);
++op;
}
}
}
queue <int> que;
for(int i = ; i < n*m; ++i) {
if(du[i] == )
que.push(i);
}
while(!que.empty()) {
int u = que.front();
que.pop();
du[u]--;
for(int i = ; i < G[u].size(); ++i) {
int v = G[u][i];
du[v]--;
if(du[v] > ) {
cnt++;
for(int j = ; j < G[v].size(); ++j) {
du[G[v][j]]--;
if(du[G[v][j]] == ) {
que.push(G[v][j]);
}
}
du[v] = ;
change(u, v);
} else if(du[v] == ) {
cnt++;
change(u, v);
}
}
}
if(cnt * == op) {
for(int i = ; i < n; ++i) {
printf("%s\n", str[i]);
}
} else {
printf("Not unique\n");
}
return ;
}

Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)的更多相关文章

  1. Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序

    B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...

  2. Codeforces Round #292 (Div. 1) - B. Drazil and Tiles

    B. Drazil and Tiles   Drazil created a following problem about putting 1 × 2 tiles into an n × m gri ...

  3. Codeforces Round #292 (Div. 2) D. Drazil and Tiles [拓扑排序 dfs]

    传送门 D. Drazil and Tiles time limit per test 2 seconds memory limit per test 256 megabytes Drazil cre ...

  4. Codeforces Round #292 (Div. 1) C. Drazil and Park 线段树

    C. Drazil and Park 题目连接: http://codeforces.com/contest/516/problem/C Description Drazil is a monkey. ...

  5. Codeforces Round #292 (Div. 2) C. Drazil and Factorial

    题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...

  6. Codeforces Round #292 (Div. 1) C - Drazil and Park

    C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...

  7. Codeforces Round #292 (Div. 2) C. Drazil and Factorial 515C

    C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. #292 (div.2) D.Drazil and Tiles (贪心+bfs)

    Description Drazil created a following problem about putting  ×  tiles into an n × m grid: "The ...

  9. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. win32窗口机制之CreateWindow

    CreateWindow     函数功能:该函数创建一个重叠式窗口.弹出式窗口或子窗口.它指定窗口类,窗口标题,窗口   风格,以及窗口的初始位置及大小(可选的).该函数也指定该窗口的父窗口或所属窗 ...

  2. C语言之宏

    所谓的宏就是一种预处理命令,什么是与处理呢?即在编译过程之前先对程序代码做出的必要的转换处理.宏有两个作用: 1.当遇到需要将程序某个特定的数量在程序中出现的所有实例通通加以修改时,程序只需改动一处即 ...

  3. BZOJ 3306 树

    dfs序建线段树+分类讨论+写的有点长. #include<iostream> #include<cstdio> #include<cstring> #includ ...

  4. VFL示例

    •[cancelButton(72)]-12-[acceptButton(50)] •取消按钮宽72point,accept按钮宽50point,它们之间间距12point • •[wideView( ...

  5. impersonate a user

    // This sample demonstrates the use of the WindowsIdentity class to impersonate a user. // IMPORTANT ...

  6. 无线端通用的reset样式

    @charset "utf-8"; html, body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, o ...

  7. Linux初识(转)

    文件系统是linux的一个十分基础的知识,同时也是学习linux的必备知识. 本文将站在一个较高的视图来了解linux的文件系统,主要包括了linux磁盘分区和目录.挂载基本原理.文件存储结构.软链接 ...

  8. 10g中HASH GROUP BY引起的临时表空间不足

    原本在9i上可以顺利完成的CTAS脚本,迁移到10g后运行总是报“ORA-1652: unable to extend temp segment by 128 in tablespace TS_HQY ...

  9. HDFS的基本概念

    转:http://www.cnblogs.com/forfuture1978/archive/2010/03/14/1685351.html

  10. ssh 或者 scp 无需输入密码的解决办法

    这里假设主机A(192.168.100.3)用来获到主机B(192.168.100.4)的文件.   在主机A上执行如下命令来生成配对密钥: ssh-keygen -t rsa   遇到提示回车默认即 ...