题目链接:http://codeforces.com/problemset/problem/847/I

I. Noise Level
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line contains four integers nmq 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.

Output

Print the number of quarters, in which the noise level exceeds the allowed level p.

Examples
input
3 3 100 140
...
A*.
.B.
output
3
input
3 3 2 8
B*.
BB*
BBB
output
4
input
3 4 5 4
..*B
..**
D...
output
7
Note

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

  1. 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 & ...

  2. 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 ...

  3. 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 排序之后优先队 ...

  4. 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: ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  6. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 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 ...

  9. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

随机推荐

  1. js、JSP、servlet之间的传递小结

    @ JS 与 JSP :JSP无法直接获取JS的值,只能通过隐藏表单或者dom节点设置. JSP中设置隐藏表单input,或者设置任意一个隐藏或者不隐藏的节点比如div, 而JS就通过document ...

  2. adb 安装apk 报错:Failure [INSTALL_FAILED_ALREADY_EXISTS]

    遇到INSTALL_FAILED_ALREADY_EXISTS问题,直接通过adb install -r xxx.apk命令安装apk即可

  3. Linux和win7(win10)双系统时间错误问题 时间相差8小时

    转载自 http://m.2cto.com/os/201204/126212.html 有修改 前一段时间刚装了centos 5.4和win7的双系统.发现win7的系统时间不对,机子没上网,每天开机 ...

  4. 【javascript】谈谈HTML5 ——HTML兽进化, H5兽!

    作为一名Web开发者,可能你并没有对这个“H5”这个字眼投入太多的关注,但实际上它早已不知不觉进入到你的开发中,并且总有一天会让你不得不正视它,了解它并运用它   打个比方:<海贼王>中的 ...

  5. Mysql 数据库date, datetime类型设置0000-00-00默认值(default)报错问题

    Mysql 数据库date, datetime类型设置0000-00-00默认值报错问题 现象:MySQL5.7版本之后,date, datetime类型设置默认值"0000-00-00&q ...

  6. Android studio 1.x 安装完毕后无法打开问题解决方案

    Android Studio 1.0正式发布,给Android开发者带来了不小的惊喜,再也不用为繁琐的环境配置而烦恼,从某一层面上说这降低了android开发门槛. 不过貌似只能开心一会儿,因为and ...

  7. spring 整合Mybatis 错误:Parameter 'items_id' not found. Available parameters are [array]

    运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:Parameter 'items_id' not found. ...

  8. CPU和GPU的差别

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt317 首先需要解释CPU和GPU这两个缩写分别代表什么.CPU即中央处理器, ...

  9. 用shell批量编码转换

    -------------------------------------文件内容转换:iconv-------------------------------------- 通常,从其他平台拷贝过来 ...

  10. 转: 【Java并发编程】之二十:并发新特性—Lock锁和条件变量(含代码)

    简单使用Lock锁 Java5中引入了新的锁机制--Java.util.concurrent.locks中的显式的互斥锁:Lock接口,它提供了比synchronized更加广泛的锁定操作.Lock接 ...