CodeForcesGym 100502E Opening Ceremony
Opening Ceremony
This problem will be judged on CodeForcesGym. Original ID: 100502E
64-bit integer IO format: %I64d Java class name: (Any)
For the grand opening of the algorithmic games in NlogNsglow, a row of tower blocks is set to be demolished in a grand demonstration of renewal. Originally the plan was to accomplish this with controlled explosions, one for each tower block, but time constraints now require a hastier solution. To help you remove the blocks more rapidly you have been given the use of a Universal Kinetic / Incandescent Energy Particle Cannon(UKIEPC).Onasingle charge, this cutting-edge contraption can remove either all of the floors in a single tower block, or all the x-th floors in all the blocks simultaneously, for user’s choice of the floor number x. In the latter case, the blocks that are less than x floors high are left untouched, while for blocks having more than x floors, all the floors above the removed x-th one fall down by one level.
Task
Given the number of floors of all towers, output the minimum number of charges needed to eliminate all floors of all blocks.
Input
The first line of input contains the number of blocks n, where 2 ≤ n ≤ 100000. The second line contains n consecutive block heights hi for i = 1,2,...,n, where 1 ≤ hi ≤ 1000000. Output Output oneline containingone integer: theminimum numberof charges needed totear down all the blocks.
Sample Input 1
6
2 1 8 8 2 3
Sample Output 1
5
Sample Input 2
5
1 1 1 1 10
Sample Output 2
2
NCPC 2014 Problem E: Opening Ceremony 9
解题:贪心,要消除一行肯定消除低的,要消除整列的话优先消除高的。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int h[maxn],n;
int main(){
while(~scanf("%d",&n)){
for(int i = ; i <= n; ++i)
scanf("%d",h+i);
sort(h+,h+n+);
int ret = n;
for(int i = ; i <= n; ++i)
ret = min(ret,n - i + h[i]);
printf("%d\n",ret);
}
return ;
}
CodeForcesGym 100502E Opening Ceremony的更多相关文章
- 贪心 Gym 100502E Opening Ceremony
题目传送门 /* 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过 ...
- Opening Ceremony(贪心)
Problem E: Opening Ceremony Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 137 Solved: 30[Submit][S ...
- 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】
[英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...
- 8659 Mine Sweeping
时间限制:500MS 内存限制:65535K提交次数:37 通过次数:15 题型: 编程题 语言: G++;GCC Description The opening ceremony of the ...
- 【托业】【新托业TOEIC新题型真题】学习笔记12-题库八-P7
155.political figure 政治人物 prominent 160.association n.协会,社团; 联合,联系; 联想; rarely adv.很少地; 罕有地; 极精彩地; 珍 ...
- English trip -- VC(情景课)5 D
Read 阅读 Listen and read. 听并读 Notice from Riverside Library Come and visit Riverside Library.The new ...
- AtCoder Beginner Contest 084 C - Special Trains
Special Trains Problem Statement A railroad running from west to east in Atcoder Kingdom is now comp ...
- 安卓开发error opening trace file: No such file or directory (2)报错原因
error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...
- maven install 读取jar包时出错;error in opening zip file
错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Failed ...
随机推荐
- Android Studio生成apk
1.菜单Build->Generate Signed APK 2.生成android.keystore,能够依据弹框去Create new一个,也可使用命令来生成android.keystore ...
- http --- 从输入URL到页面加载的过程发生了什么?
可以分为这几个大的过程: DNS解析 TCP连接 客户端发送HTTP请求 服务器处理请求并返回HTTP报文 浏览器解析渲染页面 结束 其中(1)DNS解析可以理解为主寻找这个IP地址的过程,其中如果找 ...
- Why functions - Not only for python
It may not be clear why it is worth the trouble to divide a program into functions. There are a lot ...
- 系统丢失的DLL文件问题根源解决(纯净官网下载放心)(图文详解)(博主推荐)
导言 最近,身边的朋友们,问我,他电脑的win10系统里 mfc110.dll 丢失. 其他的系统文件丢失修复,是一样的步骤. 现象 大家也许,都会有这么一个习惯,动不动则就去百度上搜索. 其实啊,这 ...
- PostgreSQL Replication之第五章 设置同步复制(1)
到目前为止,我们已经处理了基于文件的复制(或日志传送)和简单的基于流复制的设置.在两种情况中,在master上事务被提交之后,数据被提交,由slave接收.在master提交和slave实际上完全地接 ...
- codeforces 400 C Inna and Huge Candy Matrix【模拟】
题意:给出一个矩形的三种操作,顺时针旋转,逆时针旋转,对称,给出原始坐标,再给出操作数,问最后得到的坐标 画一下模拟一下操作就可以找到规律了 #include<iostream> #inc ...
- Goldengate进程的合并与拆分规范
Goldengate抽取进程的合并与拆分原则 1. 文档综述 1.1. 文档说明 本文档描述了对GoldenGate的抽取进程进行拆分和合并的基本原则和详细步骤. 1.2. 读者范围 本文 ...
- SSD-tensorflow-2 制作自己的数据集
VOC2007数据集格式: VOC2007详细介绍在这里,提供给大家有兴趣作了解.而制作自己的数据集只需用到前三个文件夹,所以请事先建好这三个文件夹放入同一文件夹内,同时ImageSets文件夹内包含 ...
- 【转载】解决django models文件修改后的数据库同步问题——south模块
转载链接:https://www.cnblogs.com/frchen/p/5732490.html 在使用django进行开发时,往往需要根据不同的需求对model进行更改.而这时候,python ...
- springboot实现热部署,修改代码不用重启服务
1.引入热部署依赖 <!-- 热部署模块 --> <dependency> <groupId>org.springframework.boot</groupI ...