Codeforces 1061B Views Matter(思维)(*1500)

本文提供了一种解决 Codeforces 1061B 题目的算法思路,通过排序和逐列分析的方法,计算出在保持从上方和右侧视角不变的情况下,最多可以移除多少个方块。此解法使用 C++ 实现,并详细解释了代码的运行逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codeforces.com/contest/1061/problem/B

题意:最多能去除多少个块使得从右面和上面看下去和原图一样

思路:先把每一列进行排序,每一列选择一个或者多个,视情况而定,拍完序就很明了了

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
#define ll long long
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    int a[100005];
    for(int i = 1; i <= n; i ++)
    {
        scanf("%d",&a[i]);
    }
    sort(a + 1, a + 1 + n);
    int h = a[n];
    ll ans = 0;
    int now = 0;
    for(int i = 1; i <= n; i ++)
    {
        if(a[i] >= now + 1)
        {
            if(now + 1 <= h)
            now ++;
            ans += (a[i] - 1);
        }
        else
        {
            ans += (a[i] - 1);
        }
    }
    //cout<<now<<endl;
    if(h == now) cout<<ans<<endl;
    else
    cout<<ans - (h - now)<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值