题目链接:

  http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1791

题目大意:

  N栋大楼(N<=100000),拆除的时候有两种选择的操作,可以拆掉一整栋,或者把当前所有大楼的第x层拆掉(高度小于x的没用),并且x以上的所有楼层高度-1.(相当于所有高于x的大楼抽掉一层)

  问把N栋大楼拆掉至少要几次拆除操作。

题目思路:

  【模拟】

  先将大楼高度排序,之后考虑分界线,枚举I,I之后的大楼都是被单个拆除,而I和I之前的大楼都是被一层一层拆除。ans=min(n-i+h[i])

  1. //
  2. //by coolxxx
  3. //#include<bits/stdc++.h>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<map>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #include<bitset>
  13. #include<memory.h>
  14. #include<time.h>
  15. #include<stdio.h>
  16. #include<stdlib.h>
  17. #include<string.h>
  18. //#include<stdbool.h>
  19. #include<math.h>
  20. #define min(a,b) ((a)<(b)?(a):(b))
  21. #define max(a,b) ((a)>(b)?(a):(b))
  22. #define abs(a) ((a)>0?(a):(-(a)))
  23. #define lowbit(a) (a&(-a))
  24. #define sqr(a) ((a)*(a))
  25. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  26. #define mem(a,b) memset(a,b,sizeof(a))
  27. #define eps (1e-8)
  28. #define J 10
  29. #define mod 1000000007
  30. #define MAX 0x7f7f7f7f
  31. #define PI 3.14159265358979323
  32. #define N 100004
  33. using namespace std;
  34. typedef long long LL;
  35. int cas,cass;
  36. int n,m,lll,ans;
  37. int h[N];
  38. bool cmp(int a,int b)
  39. {
  40. return a<b;
  41. }
  42. int main()
  43. {
  44. #ifndef ONLINE_JUDGE
  45. // freopen("1.txt","r",stdin);
  46. // freopen("2.txt","w",stdout);
  47. #endif
  48. int i,j,k;
  49. // for(scanf("%d",&cass);cass;cass--)
  50. // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
  51. // while(~scanf("%s",s+1))
  52. while(~scanf("%d",&n))
  53. {
  54. for(i=;i<=n;i++)
  55. scanf("%d",&h[i]);
  56. sort(h+,h++n,cmp);
  57. ans=min(n,h[n]);
  58. for(i=;i<n;i++)
  59. ans=min(ans,n-i+h[i]);
  60. printf("%d\n",ans);
  61. }
  62. return ;
  63. }
  64. /*
  65. //
  66.  
  67. //
  68. */

【模拟】NCPC 2014 E ceremony的更多相关文章

  1. 【模拟】NCPC 2014 D Dice Game

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1790 题目大意: 两个人,每个人有两个骰子,每个骰子可以等概率取[a,b],问哪个人两 ...

  2. 【模拟】NCPC 2014 K Train passengers

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1797 题目大意: 有N个车站,火车一共可以坐M个人,每个车站下车Ai,上车Bi个人,在 ...

  3. 模拟 Coder-Strike 2014 - Round 1 A. Poster

    题目地址:http://codeforces.com/problemset/problem/412/A /* 模拟:题目没看懂,但操作很简单,从最近的一头(如果不在一端要先移动到一端)往另一头移动,顺 ...

  4. 【高精度】NCPC 2014 C catalansqure

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1789 题目大意: 求大卡特兰数..公式如下.输入n求Sn(n<=5000) 题目 ...

  5. 【动态规划】【缩点】NCPC 2014 G Outing

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1793 题目大意: 一辆公交车,上面M个座位,N个人(M<=N<=1000) ...

  6. 【KMP】【最小表示法】NCPC 2014 H clock pictures

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1794 题目大意: 两个无刻度的钟面,每个上面有N根针(N<=200000),每个 ...

  7. 【图论】【宽搜】【染色】NCPC 2014 A Ades

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1787 题目大意: N个点M条无向边(N,M<=200000),一个节点只能有一个 ...

  8. hdu 4915 Parenthese sequence(模拟)2014多培训学校5现场

    Parenthese sequence                                                                     Time Limit: ...

  9. CodeForcesGym 100502E Opening Ceremony

    Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForces ...

随机推荐

  1. 使用PHP实现蜘蛛访问日志统计

    $useragent = addslashes(strtolower($_SERVER['HTTP_USER_AGENT'])); if (strpos($useragent, 'googlebot' ...

  2. java 钱币的单位转换

    将钱转成转换为带指定单位的钱 int money = 10; NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); System ...

  3. java的各个队列之间的联系和区别是什么

    java的各个并发队列之间的联系和区别 java.util.concurrent是在并发编程中很常用的实用工具类 ArrayBlockingQueue, DelayQueue, LinkedBlock ...

  4. 【HOJ1356】【Miller_rabin素性测试】Prime Judge

    Given a positive integer, your job is writing a program to determine whether it is a prime number or ...

  5. iOS 视频播放横屏,隐藏状态栏

    MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] init]; ...

  6. c++ undefined reference to mysqlinit

    Solved g++ $(mysql_config --cflags) file.cpp -o filename $(mysql_config --libs)

  7. 移动Web开发,4行代码检测浏览器是否支持position:fixed

    不废话,直接上代码 var div = document.createElement('div'); div.style.cssText = 'display:none;position:fixed; ...

  8. nav

    $(document).ready(function() { $(window).resize(function(){ var need=0; var ul_max_width = $(window) ...

  9. Ubuntu14.02 Sublimte2安装

    $sudo add-apt-repository ppa:webupd8team/sublime-text-2 $sudo apt-get update $sudo apt-get install s ...

  10. dictionary(字典)

    dictionary(字典):   字典对象   字典是一种key - value 的数据类型,使用就像我们上学用的字典,通过笔划.字母来查对应页的详细内容. 1.      dic={"n ...