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 ...
随机推荐
- Ryu基本操作的REST API调用演示样例
import urllib2 import json def get_all_switches(): url = "http://127.0.0.1:8080/v1.0/topology/s ...
- 图文介绍MyEclipse (2015) 中创建简单的Maven项目的步骤(用于生成可运行jar文件)
利用MyEclipse的引导,能够非常方便的创建简单的.用于生成可运行jar文件的Maven项目: (原创文章,转载请注明转自Clement-Xu的博客:http://blog.csdn.net/cl ...
- oracle 存储过程定义及调试,并终于被C# 调用 代码
C# 调用存储过程 參考了非常多文章,写了例如以下文字,算是分享吧 目的:更改积分,并作一定校验 一.一般的调试方法: 方法一:带返回out參数,必须定义变量 myresult DECLARE myr ...
- poj--1904--King's Quest(scc建图)
King's Quest Time Limit: 15000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit ...
- Numpy科学计算工具
Numpy初探 Numpy基础数据结构 Numpy数组是一个多维数组,称为ndarray.其由两部分组成: 实际的数据 描述这些数据的原数据 导入该库: import numpy as np 多维数组 ...
- python3.x 学习笔记1(基础知识)
1.python模块: 标准库和第三方库,第三方库需要下载安装 2.模块sys: 命令 功能 sys.stdin 标准输入流sys.stdout 标准输出流sys.stderr ...
- tomcat web容器工作原理
Tomcat的模块结构设计的相当好,而且其Web 容器的性能相当出色.JBoss直接就使用了Tomcat的web容器,WebLogic的早期版本也是使用了Tomcat的代码.Web容器的工作过程在下面 ...
- Kubernetes1.5 集成Heapster
Kubernetes1.5 集成Heapster Heapster是kubernetes集群监控工具.在1.2的时候,kubernetes的监控需要在node节点上运行cAdvisor作为agent收 ...
- 2017国家集训队作业[agc016b]Color Hats
2017国家集训队作业[agc016b]Color Hats 题意: 有\(N\)个人,每个人有一顶帽子.帽子有不同的颜色.现在,每个人都告诉你,他看到的所有其它人的帽子共有多少种颜色,问有没有符合所 ...
- [笔记-图论]Dijkstra
用于求正权有向图 上的 单源最短路 优化后时间复杂度O(mlogn) 模板 // Dijkstra // to get the minumum distance with no negtive way ...