题目链接:

  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. hdu 5073 Galaxy

    题意是给定n个点,让求找到一个点p使得sigma( (a[i] - p) ^ 2 ) 最小,其中a[i]表示第i个点的位置.其中有k个点不用算. 思路:发现这道题其实就是求n-k个点方差. 那么推一下 ...

  2. LiLei&HanMeiMei的隐式马尔可夫爱情

    一篇非常棒的隐马尔可夫入门文章...推荐! from: http://staffwww.dcs.shef.ac.uk/people/W.Liu/hmm.html

  3. weex APIs

    1.通过这个$vm()上下文访问这些api在脚本的方法 <script> module.exports = { methods: { somemethod: function() { th ...

  4. 关键字throw(something)限制

    C++函数后加关键字throw(something)限制,是对这个函数的异常安全性作出限制.void f() throw() 表示f不允许抛出任何异常,即f是异常安全的.void f() throw( ...

  5. mysql基础操作整理(一)

    显示当前数据库 mysql> select database(); +------------+ | database() | +------------+ | test | +-------- ...

  6. TextView控件

    1.手动创建(不建议): TextView tv = new TextView(this); tv.setContent("你好"); setContentView(tv); 2. ...

  7. java数据类型学习

    java数据类型基本分为两类: 一类为基本数据类型: 数值类型: 整数类型:byte.short.int.long 浮点类型:float.double 字符类型:char 布尔类型:boolean 一 ...

  8. win7下.NET 2.0未在web服务器上注册的问题(转)

    转自:http://blog.sina.com.cn/s/blog_6d15b547010192hx.html 电脑装了win7操作系统,装上vs2008后运行dotnetnuke项目后出现" ...

  9. Extjs 4学习2

    主要学习采自:http://www.ishowshao.com/blog/2012/06/19/extjs-4-getting-started/ 用的sdk为extjs4.2.1 根据其中的提示装了一 ...

  10. 18 4Sum(寻找四个数之和为指定数的集合Medium)

    题目意思:给一个乱序数组,在里面寻找三个数之和为target的所有情况,这些情况不能重复,增序排列 思路:采用3Sum的做法 ps:有见一种用hash的,存任意两个元素的和,然后变成3sum问题,需要 ...