Codeforces Round #292 (Div. 1) B. Drazil and Tiles (类似拓扑)
题目链接: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 (类似拓扑)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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. ...
- Codeforces Round #292 (Div. 2) C. Drazil and Factorial
题目链接:http://codeforces.com/contest/515/problem/C 给出一个公式例如:F(135) = 1! * 3! * 5!; 现在给你一个有n位的数字a,让你求这样 ...
- Codeforces Round #292 (Div. 1) C - Drazil and Park
C - Drazil and Park 每个点有两个值Li 和 Bi,求Li + Rj (i < j) 的最大值,这个可以用线段树巧妙的维护.. #include<bits/stdc++. ...
- 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 ...
- #292 (div.2) D.Drazil and Tiles (贪心+bfs)
Description Drazil created a following problem about putting × tiles into an n × m grid: "The ...
- 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 ...
随机推荐
- openerp学习笔记 context 的应用
1.在Action中定义,context用于传递搜索条件和分组条件,在搜索视图中默认显示: 示例代码: <record model="ir.actions.act_window&quo ...
- Java Cardioid 心脏形曲线 (整理)
package demo; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import jav ...
- ecshop 模版商品详情页,不同商品调用不同模板
1.在goods.php中找到以下代码 $smarty->display('goods.dwt', $cache_id); 改为下面的代码 switch ($goods['cat_id']){ ...
- swun 1766 我的悲剧不可能那么好数
解题思路: 一向提交特别慎重的我,这题竟然PE了5发左右,放了几天,再回来写,直接1A, 相当的自豪,而且是最优解题者.这题千万要注意,化繁为简,文章只包括大小 写字母和数字,还有空行. #inc ...
- jQuery.validate API
- 增加eclipse启动的Tomcat内存的
JAVA程序启动时JVM都会分配一个初始内存和最大内存给这个应用程序.这个初始内存和最大内存在一定程度都会影响程序的性能. 如何设置Tomcat的JVM内存大小 Tomcat本身不能直接在计算机上运行 ...
- java 构造函数内部的多态方法 完全剖析
我们先来看一个例子,如果你读过<java编程思想>的话 应该会有印象 package com.test.zj; public class PolyConstructors { public ...
- Android通过代码获取View
View view = LayoutInflater.from(mContext).inflate(R.layout.song_item_adapter, null); LayoutInflater ...
- loadrunner中lr_log_message和lr_output_message 的区别
LoadRunner中lr_output_message和lr_log_message(1)在vgen中,我们必须写输出函数输出信息,将我们所想要了解的信息用函数输出,主要有这么几个函数输出信息: l ...
- Linux 通过YUM安装rzsz
yum自动安装: yum install lrzsz