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
  • 相关阅读:
    Yii2 分页
    Yii2 或者当前登录用户帐号
    css3媒体查询判断移动设备横竖屏
    Javascript操作Tr隐藏显示变形~
    php注释标准
    匹配一段html中所有的src
    数据库遇到错误(随时补充)
    NetCore-缓存文件上传和文件流上传
    SVN跨服务器版本迁移
    发票同步微信卡包
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4461520.html
Copyright © 2011-2022 走看看