codeforces round 472(DIV2)D Riverside Curio题解(思维题)
题目传送门: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题解(思维题)的更多相关文章
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- 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 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
随机推荐
- ACM学习历程—HDU 5012 Dice(ACM西安网赛)(bfs)
Problem Description There are 2 special dices on the table. On each face of the dice, a distinct num ...
- POJ1456:Supermarket
浅谈堆:https://www.cnblogs.com/AKMer/p/10284629.html 题目传送门:http://poj.org/problem?id=1456 把物品按照时间排序,显然\ ...
- 洛谷【P1104】生日(冒泡排序版)
题目传送门:https://www.luogu.org/problemnew/show/P1104 题目很简单,我主要是来讲冒泡排序的. 所谓冒泡排序,流程如下: 每次确定一个\(rk\)(从\(n\ ...
- fastjson 使用笔记
1.string转json String params={'key1':'50001','key2':10007700'}Map<String, String> a = JSON.pars ...
- SpringMvc之参数绑定注解详解之二
2 consumes.produces 示例 cousumes的样例: 1 @Controller 2 @RequestMapping(value = "/pets", met ...
- web安全之同源策略
为什么使用同源策略?一个重要原因就是对cookie的保护,cookie 中存着sessionID .如果已经登录网站,同时又去了任意其他网站,该网站有恶意JS代码.如果没有同源策略,那么这个网站就能通 ...
- mysql--二进制日志(bin-log)
一.设置二进制日志 进制日志记录了所有的DDL和DML,但不包括各种查询.通过二进制日志,可以实现什么效果呢?二进制日志文件可以[实现灾难数据恢复],另外可以应用到[mysql复制数据同步].二进制日 ...
- ViewPageIndicator--仿网易的使用
仿微信(网易的界面) 第一步: AndroidManifest.xml 的配置 <?xml version="1.0" encoding="utf-8"? ...
- [hdu4372]counting buildings
解题关键: n的环排列的个数与n-1个元素的排列的个数相等. 首先可以肯定,无论从最左边还是从最右边看,最高的那个楼一定是可以看到的,从这里入手. 假设最高的楼的位置固定,最高楼的编号为n,那么我们为 ...
- p1640&bzoj1854 连续攻击游戏(游戏)
传送门(洛谷) 传送门(bzoj) 题目 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用 ...