题目传送门: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. ACM学习历程—FZU2195 检查站点(树形DP || 贪心)

    Description 在山上一共有N个站点需要检查,检查员从山顶出发去各个站点进行检查,各个站点间有且仅有一条通路,检查员下山前往站点时比较轻松,而上山时却需要额外的时间,问最后检查员检查完所有站点 ...

  2. prufer BZOJ1211: [HNOI2004]树的计数

    以前做过几题..好久过去全忘了. 看来是要记一下... [prufer] n个点的无根树(点都是标号的,distinct)对应一个 长度n-2的数列 所以 n个点的无根树有n^(n-2)种 树 转 p ...

  3. 【Sublime Text 3】编译环境

    1.默认编译时总会出现错误 报错: [Finished in 1.3s with exit code 1][cmd: ['gcc', 'V:\\Cynthia\\01.c']][dir: V:\Cyn ...

  4. poj 2000 Gold Coins(水题)

    一.Description The king pays his loyal knight in gold coins. On the first day of his service, the kni ...

  5. CCS V5 使用教程二:创建工程和配置软件仿真

    新建CCS项目 选择File/New/CCS Project: 新建项目对话框 1)        Project name: 指项目名称,这里要注意的项目名称不区分大小写. 2)        Ou ...

  6. GCC提供的几个內建函数

    参考 https://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Other-Builtins.html#Other-Builtins https://en.wikipe ...

  7. 用C语言实现中文到unicode码的转换

    转自:  http://blog.csdn.net/qq_21792169/article/details/50379275 源文件用不同的编码方式编写,会导致执行结果不一样 由于本人喜欢用Notep ...

  8. springMVC绑定json参数之一

    一.SpringMVC @RequestBody接收Json对象字符串 以前,一直以为在SpringMVC环境中,@RequestBody接收的是一个Json对象,一直在调试代码都没有成功,后来发现, ...

  9. linux日常管理-curl工具

    curl 在linux命令行中用于访问网站,下载东西, 可以用 curl www.qq.com 访问 出现很多源代码 ///////////////////////////////////////// ...

  10. qt程序异常结束crashed

    今天调试以前写的opencv的程序发现每次一点运行就报错误 Starting D:\Qt\QProjects\build-HelloWorld-lian-Debug\debug\HelloWorld. ...