码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForcesGym 100502E Opening Ceremony

时间:2015-04-27 23:34:06      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

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 ?oors in a single tower block, or all the x-th ?oors in all the blocks simultaneously, for user’s choice of the ?oor number x. In the latter case, the blocks that are less than x ?oors high are left untouched, while for blocks having more than x ?oors, all the ?oors above the removed x-th one fall down by one level.

Task

Given the number of ?oors of all towers, output the minimum number of charges needed to eliminate all ?oors of all blocks.

Input

The ?rst 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

 

解题:贪心,要消除一行肯定消除低的,要消除整列的话优先消除高的。。

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 100010;
 4 int h[maxn],n;
 5 int main(){
 6     while(~scanf("%d",&n)){
 7         for(int i = 1; i <= n; ++i)
 8             scanf("%d",h+i);
 9         sort(h+1,h+n+1);
10         int ret = n;
11         for(int i = 1; i <= n; ++i)
12             ret = min(ret,n - i + h[i]);
13         printf("%d\n",ret);
14     }
15     return 0;
16 }
View Code

 

CodeForcesGym 100502E Opening Ceremony

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4461520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!