题目传送门
1 /*
2 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列。求要消去所有的砖块需要最小的操作数
3 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过程影响,和结果无关
4 首先sort降序,选择消去列的个数,更新最小值
5 当时想复杂了,貌似是上学期校赛留下的阴影:)
6 详细解释:http://blog.csdn.net/liao_jingyi/article/details/40455311
7 */
8 #include <cstdio>
9 #include <iostream>
10 #include <algorithm>
11 #include <cstring>
12 #include <string>
13 #include <cmath>
14 #include <set>
15 #include <map>
16 #include <queue>
17 using namespace std;
18
19 const int MAXN = 1e6 + 10;
20 const int INF = 0x3f3f3f3f;
21 int a[MAXN];
22
23 bool cmp(int x, int y)
24 {
25 return x > y;
26 }
27
28 int main(void) //Gym 100502E Opening Ceremony
29 {
30 //freopen ("E.in", "r", stdin);
31
32 int n;
33 while (scanf ("%d", &n) == 1)
34 {
35 for (int i=1; i<=n; ++i)
36 {
37 scanf ("%d", &a[i]);
38 }
39
40 sort (a+1, a+1+n, cmp);
41
42 int ans = n;
43 for (int i=1; i<=n; ++i)
44 {
45 ans = min (ans, i - 1 + a[i]);
46 }
47
48 printf ("%d
", ans);
49 }
50
51
52 return 0;
53 }