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. ftoa浮点型转换成字符串

    #include <stdio.h> bool ftos(float num,char *s,int n) {     int temp; float t=num; int pn=0; b ...

  2. 用java实现螺旋数组

    接收数组的行数和列数,返回正序和倒序的螺旋数组 package cn.baokx; public class Test { public static void main(String[] args) ...

  3. springMVC怎么接收日期类型的参数?

    springMVC怎么接收日期类型的参数? springMVC的controller中用实体接受页面传递的参数,并且实体中的属性类型为日期类型,怎么接收呢?如果接收不到会进不到controller中. ...

  4. Linux 玩法

    php 跑不了,只来404 同一台linux服务器上建两个网站(www.A.com, www.B.com),现在A和B都跑起来了,但只有 A 能跑 php, B只能跑静态 html 文件,不知道哪里设 ...

  5. TabLayout禁止选择

    项目中有个页面上面是TabLayout下面是Listview,选择TabLayout的选项卡更新下面Listview里面的数据,在请求的时候想禁用TabLayout选项卡来避免用户频繁点击选项卡造成L ...

  6. Intellij使用"easyexplore"

    刚开始接触Intellij,里面有很多东西还不太会用,平时在eclipse里面用的很方便的easyexplore能帮助快速打开文件目录,Intellij中本身就有这样的功能,只是默认没有开启,需要我们 ...

  7. 关于ListView的一些不常用到的属性

    1.setCacheColorHint自定义listview的时候,当你不使用Android:cacheColorHint=“#00000000”会出现下面选中一个空间黑色底色的情况,破坏整体美观度 ...

  8. PostgreSQL Replication之第九章 与pgpool一起工作(2)

    9.2 理解pgpool的功能 pgpool提供了如下功能: •连接池 •语句级别的复制 •负载均衡 •限制连接 •内存缓存 •并行查询 [当决定使用那些功能的时候,记住并非所有的功能可以在同一时间使 ...

  9. 关于vsphere的 许可证配置问题

    exsi未获得许可情况: exsi的许可证: vcenter server 未获许可: vcenter server的许可证: 写在最后: 无所不能的中国人,百度一下  许可证 就什么多有了,佩服,佩 ...

  10. Symfony4中文文档: 安装和设置Symfony框架

    安装和设置Symfony框架 要创建新的Symfony应用程序, 首先确保使用的是PHP7.1 或更高版本并且已经安装Componser. 如果未安装, 请首先在系统上全局安装Componser. 如 ...