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
  • 相关阅读:
    如何把阿里图标库的图标生成代码并应用于自己的项目
    【记事件】
    极光推送,为什么IOS有的手机一直收不到推送。
    浮点型的数据对比。
    MySQL通过show processlist查看项目的mysql写的有问题
    thinkPHP5实现简单的多图上传
    mac终端运行/终止jar包
    referer参数和addslashes()函数的骚路子
    小技巧|addslashes绕过
    团队博客七
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4461520.html
Copyright © 2011-2022 走看看