Opening Ceremony

Time Limit: 5000ms
Memory Limit: 524288KB

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的更多相关文章

  1. 贪心 Gym 100502E Opening Ceremony

    题目传送门 /* 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过 ...

  2. Opening Ceremony(贪心)

    Problem E: Opening Ceremony Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 137  Solved: 30[Submit][S ...

  3. 【英语魔法俱乐部——读书笔记】 3 高级句型-简化从句&倒装句(Reduced Clauses、Inverted Sentences) 【完结】

    [英语魔法俱乐部——读书笔记] 3 高级句型-简化从句&倒装句(Reduced Clauses.Inverted Sentences):(3.1)从属从句简化的通则.(3.2)形容词从句简化. ...

  4. 8659 Mine Sweeping

    时间限制:500MS  内存限制:65535K提交次数:37 通过次数:15 题型: 编程题   语言: G++;GCC Description The opening ceremony of the ...

  5. 【托业】【新托业TOEIC新题型真题】学习笔记12-题库八-P7

    155.political figure 政治人物 prominent 160.association n.协会,社团; 联合,联系; 联想; rarely adv.很少地; 罕有地; 极精彩地; 珍 ...

  6. English trip -- VC(情景课)5 D

    Read 阅读 Listen and read. 听并读 Notice from Riverside Library Come and visit Riverside Library.The new ...

  7. AtCoder Beginner Contest 084 C - Special Trains

    Special Trains Problem Statement A railroad running from west to east in Atcoder Kingdom is now comp ...

  8. 安卓开发error opening trace file: No such file or directory (2)报错原因

    error opening trace file: No such file or directory (2) 这个问题的出现是因为运行的测试机android系统版本和项目api不一致导致. 改成一样 ...

  9. maven install 读取jar包时出错;error in opening zip file

    错误信息: [INFO] ------------------------------------------------------------------------ [ERROR] Failed ...

随机推荐

  1. SharePoint Search之(七)Search result- 结果源

    在使用搜索引擎的时候.非常多情况下,用户希望限定一下搜索范围,以便更加easy找到想要的结果. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvU1BGYXJ ...

  2. 阿里云X-Forwarded-For 发现tomcat记录的日志所有来自于SLB转发的IP地址,不能获取到请求的真实IP。

    1.背景:阿里云的SLB的负载均衡,在tomcat中获取不到真实IP,而是阿里的内网IP,SLB中俩台或者3台本身是局域网,这里是SLB原理,能够看看.没怎么看懂.呵呵,要细细读下. 2.须要开启to ...

  3. iOS 中client和server的 Web Service 网络通信 (1)

    当你打开你手机上新浪微博应用或者知乎应用是.你是否会去想这些显示在手机上的图片和数据时从哪里来的?又是通过如何的方法实现的?好.那么接下来就介绍是如何实现的.过程又是怎么样的.      当我们浏览着 ...

  4. django session深入

    转至原文  https://www.cnblogs.com/zhaof/p/6281468.html 基于cookie做用户验证时:敏感信息不适合放在cookie中 session依赖cookie s ...

  5. AngularJs轻松入门(二)数据绑定

    数据绑定是AngularJs中非常重要的特性,我们看一下下面的例子: <!DOCTYPE html> <html ng-app> <head lang="en& ...

  6. <Sicily>Huffman coding

    一.题目描述 In computer science and information theory, a Huffman code is an optimal prefix code algorith ...

  7. iOS开发—— Couldn't add the Keychain Item

    报错:*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn ...

  8. 【Loadrunner】Vugen录制脚本为空的解决办法

    1. ie -> 工具 -> Internet选项 - 高级 - 勾除“启动第三方浏览器扩展选项”,然后重启电脑 2. 还有一种可能,就是机器上安装了多个浏览器,从而导致出现问题,解决方法 ...

  9. 【问题:SSH】win10使用SSH链接服务器时,提示:Host key verification failed

    异常原因:当前连接新建的验证信息与之前保存的验证信息不一致,将原来的验证信息删除就可以了. 1 使用以下命令,清空之前缓存的信息.或者直接打开C:\Users\Nolan\.ssh\known_hos ...

  10. Java基础学习总结(29)——浅谈Java中的Set、List、Map的区别

    就学习经验,浅谈Java中的Set,List,Map的区别,对JAVA的集合的理解是想对于数组: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),JAVA集合可以存储和操 ...