洛谷P2879

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40924940/article/details/85020038

一不小心点开的题。。。。看了半天发现是个水题。。。

不多讲了倒是很有意思

一排牛最高的知道了,最低的知道了,知道那两头牛之间可以相互之间看见,求可能身高。。。(最低的根本没用)

a b 之间的肯定比 a b 低,那么都比最高值 -1 ,如果暴力可能能过,但是不够好,前缀和搞定。

以下AC 代码。。。有重复部分,用 map 判重 搞定。。。

#include<iostream>
#include<cstdio>
#include<map>
#include<cstring>
using namespace std;
const int maxn = 1e5+6;
int num[maxn];
map<pair<int, int>, bool > vis;
int main()
{
    int n,l,h,r;
    scanf("%d%d%d%d",&n,&l,&h,&r);
    memset(num,0,sizeof num);
    for(int i=1;i<=r;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)
            swap(x,y);
        if(!vis[make_pair(x,y)])
        {
            num[x+1]--;   
            num[y]++;    
            vis[make_pair(x,y)]=true;
        }
    }
    for(int i=1;i<=n;i++)
    {
        num[i] += num[i-1];
        printf("%d\n",h+num[i]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40924940/article/details/85020038
今日推荐