zoukankan      html  css  js  c++  java
  • CodeForcesGym 100502E Opening Ceremony

    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

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

     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
    ",ret);
    14     }
    15     return 0;
    16 }
    View Code
  • 相关阅读:
    Selenium的WebDriver API元素定位中的XPath和CSS
    Python中pytesseract库的使用以及注意事项
    Lua语言15分钟快速入门
    day 31 综合架构实时同步服务
    day 30 综合架构存储服务
    day 29 综合架构备份项目
    day 28 综合架构备份服务
    day 27 综合架构开场介绍
    操作系统磁盘管理
    操作系统定时任务
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4461520.html
Copyright © 2011-2022 走看看