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 ...
随机推荐
- 4630 no pain no game 树状数组
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4630 题意:给你N个数,然后给你M个询问,每个询问包含一个l 一个r,问你lr 这个区间中任意两个数最 ...
- PrintWriter的println问题
今天发现一个奇怪的问题,同样的代码web server部署在windows自测机器上跟linux服务器上, 在通信上出现了不一样的换行结束符. Debug发现通过PrintWriter的println ...
- Search in Rotated Sorted Array II
Question: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? W ...
- php 使用phpmailer 发送邮件(附带中文乱码的解决方法)
下载phpmailer ,在程序里包含class.phpmailer.php 类 ,这里有中文乱码的解决方法 实例代码如下 <html> <head> <title&g ...
- JSONP实例
JSONP实例 package sus.app; import java.io.IOException; import java.util.Map; import javax.servlet.http ...
- <转+改>Web测试中关于登录的测试
请问,你为自己写过的用例怀疑过吗? 前两天听一个朋友说他同事写了100个用例,结果有92个是无效的,差点被公司开了,本人以前也写过不少用例,但现在忽然怀疑我的用例了,觉得越来越糊涂了,拿登陆框来说吧, ...
- Visual Studio下Qt调用IDL
一.简单介绍: 1.ActiveQt包含QAxContainer和QAxServer组件. 1) QAxContainer允许使用COM对象,并且可以将ActiveX控件嵌入到Qt程序中去. QAxC ...
- CH340在STM32实现一键下载电路
在做基于STM32的多功能MP3播放器的课题时,在程序下载这部分时借鉴了正点原子开发板上的一键下载电路,采用CH340G这款芯片设计. 在画PCB初期原理图部分,对采用CH340G设计的一键下载电路不 ...
- dword word byte 相互转换 .xml
pre{ line-height:1; color:#800080; background-color:#d2c39b; font-size:16px;}.sysFunc{color:#627cf6; ...
- sql server 2008 r2 出问题
1.想利用sql2008的数据挖掘功能,以为是没有安装全,所以就卸载了. (1)利用Windows Installer Clean UP将以前的卸载干净 (2)出现了Could not open ke ...