2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
题目链接:http://codeforces.com/problemset/problem/847/I
5 seconds
256 megabytes
standard input
standard output
The Berland's capital has the form of a rectangle with sizes n × m quarters. All quarters are divided into three types:
- regular (labeled with the character '.') — such quarters do not produce the noise but are not obstacles to the propagation of the noise;
- sources of noise (labeled with an uppercase Latin letter from 'A' to 'Z') — such quarters are noise sources and are not obstacles to the propagation of the noise;
- heavily built-up (labeled with the character '*') — such quarters are soundproofed, the noise does not penetrate into them and they themselves are obstacles to the propagation of noise.
A quarter labeled with letter 'A' produces q units of noise. A quarter labeled with letter 'B' produces 2·q units of noise. And so on, up to a quarter labeled with letter 'Z', which produces 26·q units of noise. There can be any number of quarters labeled with each letter in the city.
When propagating from the source of the noise, the noise level is halved when moving from one quarter to a quarter that shares a side with it (when an odd number is to be halved, it's rounded down). The noise spreads along the chain. For example, if some quarter is located at a distance 2 from the noise source, then the value of noise which will reach the quarter is divided by 4. So the noise level that comes from the source to the quarter is determined solely by the length of the shortest path between them. Heavily built-up quarters are obstacles, the noise does not penetrate into them.
The values in the cells of the table on the right show the total noise level in the respective quarters for q = 100, the first term in each sum is the noise from the quarter 'A', the second — the noise from the quarter 'B'.
The noise level in quarter is defined as the sum of the noise from all sources. To assess the quality of life of the population of the capital of Berland, it is required to find the number of quarters whose noise level exceeds the allowed level p.
The first line contains four integers n, m, q and p (1 ≤ n, m ≤ 250, 1 ≤ q, p ≤ 106) — the sizes of Berland's capital, the number of noise units that a quarter 'A' produces, and the allowable noise level.
Each of the following n lines contains m characters — the description of the capital quarters, in the format that was described in the statement above. It is possible that in the Berland's capital there are no quarters of any type.
Print the number of quarters, in which the noise level exceeds the allowed level p.
3 3 100 140
...
A*.
.B.
3
3 3 2 8
B*.
BB*
BBB
4
3 4 5 4
..*B
..**
D...
7
The illustration to the first example is in the main part of the statement.
题解:从每个噪音源点bfs(),然后统计值就可以
#include<bits/stdc++.h>
#define pb push
#define ll long long
#define PI 3.14159265
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f;
ll n,m,q,p;
bool vis[maxn][maxn];
char mp[maxn][maxn];
int sd[maxn][maxn];
int dx[]={-,,,};
int dy[]={,,-,};
struct node
{
int x,y,z;
};
void bfs(int x,int y)
{
node a,next;
a.x=x;a.y=y;a.z=(mp[x][y]-'A'+)*q;
queue<node>qq;
qq.pb(a);
sd[x][y]+=a.z;
memset(vis,false,sizeof(vis));
vis[x][y]=true;
while(!qq.empty())
{
a=qq.front();
qq.pop();
// if(a.z<=0)continue;
for(int i=;i<;i++)
{
next.x=a.x+dx[i];
next.y=a.y+dy[i];
next.z=a.z/;
if(next.x<||next.x>n||next.y<||next.y>m||mp[next.x][next.y]=='*'||vis[next.x][next.y])continue;
vis[next.x][next.y]=true;
sd[next.x][next.y]+=next.z;
if(next.z>)qq.pb(next);
}
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
cin>>n>>m>>q>>p;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>mp[i][j];
}
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(mp[i][j]>='A'&&mp[i][j]<='Z')
{
bfs(i,j);
}
}
} int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(sd[i][j]>p)ans++;
}
}
cout<<ans<<endl;
return ;
}
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)的更多相关文章
- D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage A. Union of Doubly Link ...
- 2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage(11/12)
2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage A. Coffee Break 排序之后优先队 ...
- 2019.04.18 第六次训练 【2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage】
题目链接: https://codeforces.com/gym/101911 又补了set的一个知识点,erase(it)之后it这个地址就不存在了,再引用的话就会RE A: ✅ B: ✅ C: ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)
i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结
第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...
随机推荐
- html:table属性cellpadding
cellpadding:单元格边距(空白区域) colspan:可以横跨的列数(td/th都算一列) 详细:http://www.dreamdu.com/xhtml/attribute_cellpad ...
- java内存管理(堆、栈、方法区)
java内存管理 简介 首先我们要了解我们为什么要学习java虚拟机的内存管理,不是java的gc垃圾回收机制都帮我们释放了内存了吗?但是在写程序的过程中却也往往因为不懂内存管理而造成了一些不容易察觉 ...
- 基于SSM实现的简易员工管理系统
之前自学完了JAVA基础,一直以来也没有做什么好玩的项目,最近暑假,时间上比较空闲,所以又学习了一下最近在企业实际应用中比较流行的SSM框架,以此为基础,通过网络课程,学习编写了一个基于SSM实现的M ...
- 主从及转发DNS搭建
author:JevonWei 版权声明:原创作品 主DNS 安装bind软件包 yum -y install bind systemctl start named systemctl enable ...
- el-input监听不了回车事件
vue使用element-ui的el-input监听不了回车事件,原因应该是element-ui自身封装了一层input标签之后,把原来的事件隐藏了,所以如下代码运行是无响应的: <el-inp ...
- javaScript数组去重方法
在JAvascript平时项目开发中经常会用到数组去重的操作.这时候就要用到JS数组去重的方法了. demo1: 第一种:JS数组去重操作方法是利用遍历原数组,利用数组的indexOf()方法来来判断 ...
- 手机端rem适应
这段时间做了几个手机版的项目,因为没有用框架,所以用rem来做适应,下面就分享一下 //第一种是比较简单的代码 (function(win) { resizeRoot(); function resi ...
- 通过createObjectURL实现图片预览
实现原理:通过createObjectURL 创建一个临时指向某地址的二进制对象. 过程:点击触发隐藏的 input file 的点击事件,使用createObjectURL读取 file,创建 ...
- linux一周学习总结
对于linux,之前也完全没有接触过,完全零基础小白.来到马哥以后,进入学习也有一周时间 ,一周里老师带我们学习了很多指令,下面,我就自己的理解和老师讲授的内容对linux中的一些指令做一个简单的小总 ...
- Web应用程序的开发步骤
Web应用程序的开发步骤 如今已进入了web2.0高速发展的互联网时代,各种互联网的Web应用程序如雨后春笋般出现.那么作为一名Web开发人员,怎样去开发一款优秀的Web应用程序呢?这个问题没有一个简 ...