题目传送门:http://codeforces.com/contest/957/problem/D

题意大致是这样的:有一个水池,每天都有一个水位(一个整数)。每天都会在这一天的水位上划线(如果这个水位已经被划线了,那么不划线)。

现在告诉你每天能看见的线条mi(就是高于水面的,刚好在水面的不算),设di为第i天水面以下的线条数(刚好在水面的不算),求(d1+d2+d3....dn)的最小值。

解析:

我们设第i天有ki条水位线,容易得到:

移项后,将d留在右边,我们发现mi和n都是固定的,所以,我们要让ki尽量小,此时,聪明的你一定想到了不等式。

我们发现:

我们先对m进行排序,从大到小对b(k的最小值)不断更新。

第二遍,我们从1到n扫一遍b,如果

那么将答案答案加上

具体看代码:(PS:博主最近想表白,祝我成功)

#include <bits/stdc++.h>
using namespace std;
#define _l long long
+;
int n,a[N],b[N];
_l ans=;
bool flg[N];
struct T{int x,p;}h[N];
bool cmp(T A,T B){return A.x<B.x;}
int main(){
    scanf("%d",&n);
    ;_l sig=;
    ;i<=n;i++)scanf(;
    sort(h+,h++n,cmp);
    ;i--)b[h[i].p-]=max(b[h[i].p-],h[i].x);
    ;--i)b[i-]=max(b[i-],b[i]-);
    ;i<n;++i)b[i+]=max(b[i+],b[i]);
    ;i<=n;i++){
        ;
        ){
            tmp=a[i]+;flg[i]=;b[i]=;ans+=b[i];continue;
        }
        if(flg[i]){
            b[i]=max(b[i],b[i-]+a[i]-tmp+);
        }]);tmp=max(tmp,b[i]);
        ans+=b[i];
    }
    printf("%I64d",ans-(_l)n-sig);
}

codeforces round 472(DIV2)D Riverside Curio题解(思维题)的更多相关文章

  1. Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)

    题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...

  2. Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题

    Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...

  3. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  4. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

  5. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  6. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  7. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  8. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  9. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

随机推荐

  1. Arc066_E Addition and Subtraction Hard

    传送门 题目大意 给定一个加减法的表达式,让你任意的添加合法的括号对,使的表达式最大. 题解 考虑到任意左括号一定加在减号右边,那么对于第一个左括号,与该左括号相邻的只含有加号的子序列的贡献一定为负, ...

  2. 洛谷【P2005】A/B Problem II

    题目传送门:https://www.luogu.org/problemnew/show/P2005 高精除低精:https://www.cnblogs.com/AKMer/p/9724556.html ...

  3. C#分词算法

    本文用到的库下载:点此下载 词库下载:点此下载 将词库直接放到项目根目录 词库设置如下: 类库说明 词库查看程序:点此下载 可以在上面的程序中添加常用行业词库 还可以通过下面的类在程序中实现 完整的盘 ...

  4. Azure xplate cli创建虚拟机

    Azure的管理工具多种多样.其中Portal和PowerShell是经常使用的. 但用MAC和Linux的同学最喜欢的还是Bash环境. Azure也提供了跨平台的命令行工具:Azure xplat ...

  5. CRT Library Features

    CRT Library Features The new home for Visual Studio documentation is Visual Studio 2017 Documentatio ...

  6. Python模块-subprocess模块

    Run()方法 >>> a = subprocess.run(['df','-h']) 文件系统 容量 已用 可用 已用% 挂载点 udev 468M 0 468M 0% /dev ...

  7. hibernate 数据关联多对多

    多对多,必须有一张关系表来维持关系 数据库student,teacher student_teacher 三张表 但是在pojo中只需要建立student和teacher两个类,除非关系表也代表某种业 ...

  8. numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵

    Return an array of ones with the same shape and type as a given array. Parameters: a : array_like Th ...

  9. 7.JasperReports学习笔记7-applet打印

    转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html 打包applet的class和所需的jar包,并加上数字签名 要运行打印 ...

  10. 0011_练习题d1

    __author__ = 'qq593' #!/usr/bin/env python #-*- coding:utf-8 -*- #使用while循环输入1 2 3 4 5 6 8 9 10 a=1 ...