题目链接:

  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)的更多相关文章

  1. 【宽搜】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) ...

  2. 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...

  3. 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...

  4. codeforces gym 100825 D Rings

    这题果然就是个暴力题.... 看每个T的四个方向,有'.',或者在边界上就填1 不然就填四个方向上最小的那个数再加1 然而写wa了几发,有点蠢... #include <bits/stdc++. ...

  5. 【宽搜】BAPC2014 J Jury Jeopardy (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  6. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  7. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  8. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  9. Colorado Potato Beetle(CF的某道) & 鬼畜宽搜

    题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...

随机推荐

  1. Python之路【第十三篇】:jQuery -暂无内容-待更新

    Python之路[第十三篇]:jQuery -暂无内容-待更新

  2. (转载)记录函数 getStyle() 获取元素 CSS 样式

    设置元素(element)的css属性值可以用element的style属性,例如要将element的背景色设置为黑色,可以这么做: element.style.backgroundColor = ' ...

  3. KineticJS教程(1-2)

    1.基本结构 KineticJS首先是要绑定到HTML页面上的一个DOM容器元素上,比如最常用的<div>标签.KineticJS在此容器中创建一个称之为舞台(stage)的结构,这个舞台 ...

  4. 遍历id,根据id作为条件循环查询。

    string id = "OE09924008161405102,OE36765709071405102,OE87852044171405102,OE09924008161405102&qu ...

  5. Eclipse从数据库逆向生成Hibernate带注解的实体类

    http://www.2cto.com/database/201501/372023.html

  6. iOS NSData简单解析

    iOS 基本数据类型之NSData 1 nsdata 作用: 用于存储二进制的数据类型 nadat类提供一种简单的方式,它用来设置缓存区.将文件的内容读入到缓存区.或者将缓存区中的内容写到一个文件. ...

  7. 百度地图API地址转换成经纬度

    public class LngAndLatUtil { public static Map<String,Double> getLngAndLat(String address){ Ma ...

  8. Linux下定时备份数据库

    linux下使用crontab定时备份MYSQL数据库的方法只需按照下面3步做,一切都在你的掌控之下: 第一步:在服务器上配置备份目录代码: mkdir /var/lib/mysqlbackup cd ...

  9. linux系统删除空间后系统分区空间仍不释放问题

    总结的原因: 1.删除文件文件后没有清空回收站; 2.删除的文件不在系统分区,在其他分区上; 3.删除的文件被保留在了/tmp分区下,而/tmp分区不是独立的分区,是在根分区/的基础上划分出来的分区; ...

  10. CentOS 6.4编译安装淘宝web服务器Tengine

    Tengine 是由淘宝核心系统部基于Nginx开发的Web服务器,它在Nginx的基础上,针对大访问量网站的需求,添加了很多功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,淘宝商城 ...