【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)
题目链接:
http://codeforces.com/gym/100825
题目大意:
给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空的为'.',如果最内圈<10,每个格子用两位表示,否则用三位,不足的用'.'补足。
题目思路:
【宽搜】
初始所有点标记为INF,先将图上所有的'.'标记为0,边缘如果有'T'记为1,并把'.'和边缘所有的点加入队列,接下来一个一个上下左右扩展并更新答案,没进队的进队。最后输出。
//
//by coolxxx
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define mem(a,b) memset(a,b,sizeof(a))
#define eps (1e-10)
#define J 10000
#define mod 1000000007
#define MAX 0x7f7f7f7f
#define PI 3.14159265358979323
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define N 104
#define M 10004
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int q[M][];
int a[N][N];
bool u[N][N];
char s[N][N];
void spfa()
{
int x,y,l=,r=cas;
while(l!=r)
{
x=q[l=(l+)%M][],y=q[l][];
cass=max(cass,a[x][y]);
u[x][y]=;
if(x+<=n && a[x+][y]>a[x][y]+)
{
q[r=(r+)%M][]=x+,q[r][]=y;
u[x+][y]=;
a[x+][y]=a[x][y]+;
}
if(y+<=m && a[x][y+]>a[x][y]+)
{
q[r=(r+)%M][]=x,q[r][]=y+;
u[x][y+]=;
a[x][y+]=a[x][y]+;
}
if(x-> && a[x-][y]>a[x][y]+)
{
q[r=(r+)%M][]=x-,q[r][]=y;
u[x-][y]=;
a[x-][y]=a[x][y]+;
}
if(y-> && a[x][y-]>a[x][y]+)
{
q[r=(r+)%M][]=x,q[r][]=y-;
u[x][y-]=;
a[x][y-]=a[x][y]+;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
// init();
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
cas=;cass=;mem(u,);mem(a,MAX);
scanf("%d",&m);
for(i=;i<=n;i++)
{
scanf("%s",s[i]+);
for(j=;j<=m;j++)
{
if(s[i][j]=='.')
{
q[++cas][]=i,q[cas][]=j;
a[i][j]=;
}
else if(i== || i==n || j== || j==m)
{
q[++cas][]=i,q[cas][]=j;
a[i][j]=;
}
}
}
spfa();
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
printf("%d ",a[i][j]);
puts("");
}
*/
if(cass<)
{
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
printf(".");
if(a[i][j]==)printf(".");
else printf("%d",a[i][j]);
}
puts("");
}
}
else
{
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
printf(".");
if(a[i][j]==)printf("..");
else if(a[i][j]<)printf(".%d",a[i][j]);
else printf("%d",a[i][j]);
}
puts("");
}
} }
return ;
}
/*
// //
*/
【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)的更多相关文章
- 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...
- 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...
- 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...
- codeforces gym 100825 D Rings
这题果然就是个暴力题.... 看每个T的四个方向,有'.',或者在边界上就填1 不然就填四个方向上最小的那个数再加1 然而写wa了几发,有点蠢... #include <bits/stdc++. ...
- 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- POJ1426 Find The Multiple (宽搜思想)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24768 Accepted: 102 ...
- Colorado Potato Beetle(CF的某道) & 鬼畜宽搜
题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...
随机推荐
- HttpContext.Current
HttpContext. Response 直接这样写会报错 是因为 httpcontext没有提供response 这个静态的方法. 通过这样写就可以 ASP.NET还为它提供了一个静态属性Http ...
- (转)resize扩展
jquery 默认的resize只能监听到浏览器窗口大小的改变,但我们在实际使用过程中有可能还需要监听某个div或其它标签的大小改变来执行相应的处理,如果使用默认的resize就无能为力了.怎么办呢, ...
- Axiom3D学习日记 0.Axiom基础知识
Axiom 3D Engine An open-source, cross-platform, managed 3D rendering engine for DirectX, XNA and Ope ...
- Android WebView和JavaScript交互
JavaScript在现在的网页设计中用得很多,Android 的WebView可以载入网页,WebView也设计了与JavaScript通信的桥梁.这篇主要介绍一下WebViewk控件如何和Java ...
- Eclipse设立不格式化注释
From:http://www.educity.cn/wenda/467693.html Eclipse设置不格式化注释 注释中写点带格式的文字,format后全乱了,解决办法如下: Windows ...
- c# 双问号运算
model.id??0 ??运算:如果运算符左边的值为NULL侧返回右边的值,否则返回左边的值
- switch语法之PHP
$a = 100; switch ($a) { case 100: echo '满分'; break; case $a >=60: echo '及格'; break; }
- KAFKA分布式消息系统[转]
KAFKA分布式消息系统 转自:http://blog.chinaunix.net/uid-20196318-id-2420884.html Kafka[1]是linkedin用于日志处理的分布式消 ...
- An App ID with Identifier 'xxxxxx’ is not available. Please ....
1.完全关闭Xcode; 2.找到钥匙串,将钥匙串(Keychain)中的对应证书移除: 3.再次打开Xcode,通过 Preferences - Account 4. 删除原先的账号重新登录, 搞定 ...
- Invalid project description overlaps the location of another project [android]
解决办法: 1.将工程放到其他目录下,然后执行Android工程的导入,导入时可以选择“Copy projects into workspace”: 2.不用Android工程导入,而用普通的工程导入 ...