• 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)


    题目链接: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 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=260;
    const int inf=0x3f3f3f3f;
    ll n,m,q,p;
    bool vis[maxn][maxn];
    char mp[maxn][maxn];
    int sd[maxn][maxn];
    int dx[4]={-1,1,0,0};
    int dy[4]={0,0,-1,1};
    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'+1)*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=0;i<4;i++)
            {
                next.x=a.x+dx[i];
                next.y=a.y+dy[i];
                next.z=a.z/2;
                if(next.x<1||next.x>n||next.y<1||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>0)qq.pb(next);
            }
        }
    }
    int main()
    {    
        std::ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin>>n>>m>>q>>p;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>mp[i][j];
             } 
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(mp[i][j]>='A'&&mp[i][j]<='Z')
                {
                    bfs(i,j);
                }
            }
        }
            
        int ans=0;
            for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(sd[i][j]>p)ans++; 
            }
        }
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    Intellij IDEA调试功能使用总结
    193.数据库备份和恢复
    191.数据安全性控制
    192.数据完整性管理
    190.事务管理与并发控制
    189.存储过程和触发器
    云笔记项目-笔记列表弹出"分享移动删除"子菜单
    使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送
    二进制学习
    云笔记项目-网页端debug功能学习
  • 原文地址:https://www.cnblogs.com/lhclqslove/p/7577431.html
Copyright © 2020-2023  润新知