题目链接: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. MySQL内存表-临时表

    HEAP表是访问数据速度最快的MySQL表,他使用保存在内存中的散列索引.但如果MySQL或者服务器重新启动,表中数据将会丢失.用法:如论坛的在线人数统计,这种表的数据应该是无关紧要的,就几个简单的字 ...

  2. .htaccess 文件的使用

    用于服务器对文件夹的控制 官方解释为 :分布式配置文件 ,提供了针对目录改变配置的方法; 项目可以有多个这样的配置文件,子目录文件会覆盖父目录的配置 在apache(这里泛指服务器)中,/conf/v ...

  3. ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)

    不论是单实例还是RAC,对于非缺省端口下(1521)的监听器,pmon进程不会将service/instance注册到监听器,即不会实现动态注册.与单实例相同,RAC非缺省端口的监听器也是通过设置参数 ...

  4. 《A Tour of PostgreSQL Internals》学习笔记——进程间通信

    中秋节假期这么快就没了,这几天还一直下雨,索性在家看看书.这次看的是Tom Lane的<A Tour of PostgreSQL Internals>.这篇小随笔就算做学习笔记了.园子里面 ...

  5. android 性能优化大纲

    性能优化系列 分为三个部分:视图篇 逻辑篇  和代码规范篇 . ------2016/9/6  视图篇      主要涵盖视图树层级优化.自定义视图.图片优化,常用布局性能缺陷等多个方面 .把平常经常 ...

  6. 我的window平台下的软件

    SocksCap64-Portable-3.0(配合google drive 使用) ShadowsocksR-win-3.7.4 dropbox xx-net chrome switchyomega ...

  7. 一致性Hash算法在Memcached中的应用

    前言 大家应该都知道Memcached要想实现分布式只能在客户端来完成,目前比较流行的是通过一致性hash算法来实现.常规的方法是将server的hash值与server的总台数进行求余,即hash% ...

  8. matlab 调用VLfeat库开篇问题

    准备工作见此网站 :http://cnyubin.com/?p=85 保存关闭startup.m文件后 重新打开matlab后 在命令行输入path或者vl_version无法检测到库已安装到matl ...

  9. DHTML 教程学习进度备忘

    书签:跳过:另外跳过的内容有待跟进 __________________ 学习资源:W3School. _________________ 跳过的内容: 1.这个学习进度和前面几个学习进度,只是学习了 ...

  10. 我的日常工具——gdb篇

    我的日常工具——gdb篇 03 Apr 2014 1.gdb的原理 熟悉linux的同学面试官会问你用过gdb么?那好用过,知道gdb是怎么工作的么?然后直接傻眼... gdb是怎么接管一个进程?并且 ...