Codeforces Round #523 (Div. 2) B. Views Matter

B. Views Matter

题目链接https://codeforc.es/contest/1061/problem/B

题意:

给一个类似棋盘的东西,对于每一列都放有格子,问在无重力的条件下,最多可以抽取多少个格子,并且使纵向视图和横向视图保持原样。

题解:

这题还是采用贪心的方法,先排个序,这并不影响结果。

对于每一列,肯定有一个棋子来满足纵向视图,然后尽可能地将它往高处放来满足横向视图,前提是高度低于它的横向视图已经有棋子了。

代码如下:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 100005;
int n,m;
int a[N];
ll sum = 0;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
    sort(a+1,a+n+1);
    int y = 0,x = 0;
    for(int i=1;i<=n;i++){
        x++;
        if(a[i]>y) y++;
    }
    ll ans = 0;
    ans = a[n]-y+x;
    printf("%lld",sum-ans);
    return 0;
}

原文地址:https://www.cnblogs.com/heyuhhh/p/10017481.html

时间: 2024-08-02 04:53:20

Codeforces Round #523 (Div. 2) B. Views Matter的相关文章

Codeforces Round #523 (Div. 2) Solution

A. Coins Water. 1 #include <bits/stdc++.h> 2 using namespace std; 3 int n, s; 4 5 int main() 6 { 7 while (scanf("%d%d", &n, &s) != EOF) 8 { 9 int res = 0; 10 for (int i = n; i >= 1; --i) while (s >= i) 11 { 12 ++res; 13 s -=

Codeforces Round #523 (Div. 2) C. Multiplicity

C. Multiplicity 题目链接:https://codeforc.es/contest/1061/problem/C 题意: 给出一串数,问它的"好序列"有多少.好序列的定义是,首先是一个子序列(顺序可以打乱),其次,序列相应位置的数可以除尽该位置编号. 题解:这题是dp,我没有想到,主要是状态的定义. 定义dp(i,j):在a1,a2...ai中长度为j的好序列的个数,这样dp转移方程就为:if ai%j==0:  dp(i,j)=dp(i-1,j-1)+dp(i-1,j)

Codeforces Round #523 (Div. 2) D. TV Shows

传送门 https://www.cnblogs.com/violet-acmer/p/10005351.html 题意: 有n个节目,每个节目都有个开始时间和结束时间. 定义x,y分别为租电视需要的花费和组完后 原文地址:https://www.cnblogs.com/violet-acmer/p/10050210.html

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

Codeforces Round #258 (Div. 2) A. Game With Sticks(数学题)

题目链接:http://codeforces.com/contest/451/problem/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

Codeforces Round #258 (Div. 2/A)/Codeforces451A_Game With Sticks

解题报告 http://blog.csdn.net/juncoder/article/details/38102263 n和m跟木棍相交,问一人取一交点(必须是交点,且取完后去掉交点的两根木棍),最后谁赢 思路: 取最大正方形,以对角线上的交点个数判断输赢. #include <iostream> #include <cstdio> using namespace std; int main() { int m,n; while(cin>>n>>m) { i

Codeforces Round #486 (Div. 3) A. Diverse Team

Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students

Codeforces Round #587 (Div. 3) B - Shooting

原文链接:https://www.cnblogs.com/xwl3109377858/p/11564214.html Codeforces Round #587 (Div. 3) B - Shooting Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a ta

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i