【宽搜】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教学.... 离散化宽搜, ...
随机推荐
- java返回参数中几种常见的方法
1.有参数有返回值 public class text_1 { 1)创建add方法 public int add(int i, int j) { int res = i + j; ...
- 【原】ios tableViewCell 自适应高度
原文:http://www.cnblogs.com/A--G/p/4819051.html 前言:之前在做一个类似微博的小需求时候,用table view实现了微博文字和图片等等的基本展示,由于文字和 ...
- Session技术详解
1.session简介 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务器程 ...
- kvo深入浅出举例
一,概述 KVO,即:Key-Value Observing,它提供一种机制,当指定的对象的属性被修改后,则对象就会接受到通知.简单的说就是每次指定的被观察的对象的属性被修改后,KVO就会自动通知 ...
- asp.net 在线人数统计\页面访问量
1.新建网站,添加几个窗体.webForm1.aspx ,ViewStateForm.aspx 2.在网站的根目录下添加全局应用程序类“Global.aspx” .(重要) 3.在“Global.as ...
- 2016年9月ccf
去长沙理工考ccf.恰好又可以见闺蜜. 前2道题很简单,第三题题目太长就跳过了[绕来绕去就像“你儿子是我儿子的爸爸一样头疼”],就做第四题.但是还有最后一个部分没写写好就到点了. 现在把它补充完整. ...
- opencv有关错误及解决办法
1.载入图片时内存溢出情况,如图: 分析及解决办法:因为载入的图片太大,导致内存溢出.所以更换小一点的图片就行了. 2.
- js submit的問題
form 里面有input name="submit"的时候 $('#seachform').submit();不起作用
- dede操作成功信息提示修改
函数修改 include/common.func.php 文件 function ShowMsg()函数
- Java包详解
背景: 在java中要求文件名和类名相同,所以如果把多个类放在一起,就可能出现文件名冲突 所以用包来解决,一个包中可以包含多个类 包是java提供的一种用于区别类的名字空间的机制,是类的组织方式,是一 ...