【codeforces 516B】Drazil and Tiles
题目链接:
http://codeforces.com/problemset/problem/516/B
题解:
首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解。然后如果这个图边双联通无唯一解。
同时观察可知,只有一条边的点只有唯一一种连法,所以我们可以直接将其与其相连点从图中删除,再考虑剩下图中是否还有只有一条边的点,直到所有的结点都被删除,或剩下双联通分量以及存在没有边的结点为止。
正确性……显然吧。时间复杂度$O(n^{2})$。
代码:
#include<cstdio>
inline int read(){
int s=,k=;char ch=getchar();
while(ch<''||ch>'') k=ch=='-'?-:k,ch=getchar();
while(ch>&&ch<='') s=s*+(ch^),ch=getchar();
return s*k;
}
const int N=;
int n,m;
char map[N][N];
char result[N][N];
struct node {
int x,y;
};
node q[N*N];
int l,r;
int xx[]={,-,,},yy[]={,,,-};
char z[]={'^','v','<','>','v','^','>','<'};
int pan(int x,int y){
int ans=;
for(int i=;i<;i++){
int nx=x+xx[i],ny=y+yy[i];
if(map[nx][ny]=='.') ans++;
}
return ans;
}
inline bool solve(){
int sum=;
for(int i =;i<=n;i++)
for(int j=;j<=m;j++){
if(map[i][j]=='*'){
result[i][j]=map[i][j];
continue;
}
sum++;
int t=pan(i,j);
if(t==) return ;
else if(t==) q[r++]=(node){i,j};
}
if(sum&) return false;
int t=;
while(l<r){
node now=q[l++];
int x=now.x,y=now.y;
if(map[x][y]!='.') continue;
for(int i=;i<;i++){
int nx=x+xx[i],ny=y+yy[i];
if(map[nx][ny]=='.'){
t++;
map[x][y]=;
map[nx][ny]=;
result[x][y]=z[i];
result[nx][ny]=z[i+];
for(int j=;j<;j++){
int tx=nx+xx[j],ty=ny+yy[j];
if(map[tx][ty]=='.'){
int t=pan(tx,ty);
if(t==) q[r++]=(node){tx,ty};
if(t==) return false;
}
}
break;
}
if(i==) return false;
}
}
return t>=sum/;
}
int main(){
n=read(),m=read();
for(int i=;i<=n;result[i][m+]='\n',i++)
scanf("%s",map[i]+);
bool ans=solve();
// printf("\n");
if(ans){
for(int i=;i<=n;i++)
for(int j=;j<=m+;j++){
printf("%c",result[i][j]);
}
}
else printf("Not unique\n");
}
【codeforces 516B】Drazil and Tiles的更多相关文章
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
- 【codeforces 515A】Drazil and Date
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- 锋利的Jquery摘要
一本好书值得去反复回味 第一章: jquery中的$(document).ready(function(){})与js中的windows.onload()的比较 $(document).ready ...
- 轻松解决oracle11g 空表不能exp导出的问题
轻松解决oracle11g 空表不能exp导出的问题 [引用 2012-9-22 18:06:36] 字号:大 中 小 oracle11g的新特性,数据条数是0时不分配segment,所以就不 ...
- Mybatis 系列8
上篇系列7 介绍了insert.update.delete的用法, 本篇将介绍select.resultMap的用法. select无疑是我们最常用,也是最复杂的,mybatis通过resultMap ...
- Cesium 云服务
前言 所有行业内都知道云是未来或者现在的趋势,但是真正的完完全全提供地理信息云服务的恐怕只有 Google 一家,然而今天我居然发现 Cesium 提供了云服务,你没有看错,就是曾经的开源 3D 渲染 ...
- App免费推广途径概要
说在前面的话:免费其实挺花功夫的,所有的营销的前提是产品和服务是值得推荐的. 1.技术操作维度:ASO,SEO, ASO简单介绍:http://baike.baidu.com/subview/1368 ...
- Visual Studio Live Share不完全指北
Visual Studio Live Share是什么? 是VS的一个实时协作开发的扩展工具. github地址:https://github.com/MicrosoftD...文档地址:https: ...
- IE浏览器getElementsByTagName方法的兼容问题
今天发现了一个非常可笑的IE兼容问题,环境是IE8,调用getElementsByTagName方法搜索元素,结果集居然自动识别元素的id作为键名,去掉元素定义id才能按正常的数字索引返回. 因为网页 ...
- 分享一下 常用的转换方法(例如:数字转金钱,文本与html互转等)
public sealed class SAFCFormater { /// <summary> /// 文本格式到HTML /// </summary> /// <pa ...
- php面向对象中的魔术方法
原创,转载请注明出处 在 PHP 中以两个下划线开头的方法,__construct(), __destruct (), __call(), __callStatic(),__get(), __set( ...
- SpringMVC SessionAttributes 简述
使用SpringMVC时,我们会发现网络上有关SessionAttributes注解的内容非常少,更多的人甚至推荐你继续用HttpServletRequest中的session管理方法来控制Sessi ...