题目:An integer N>=2 is given. A collection of N(N+1) soccer players, no two of whom are of the same height,
stand in a row. Sir Alex wants to remove N(N-1) players from this row leaving a new row of 2N players in
which the following N conditions hold:
(1) no one stands between the two tallest players,
(2) no one stands between the third and fourth tallest players,
......
(N) no one stands between the two shortest players.
Show that this is always possible.
题目大意:给定N(N+1)个互不相同的数,证明一定可以从中删除N(N-1)个数,使得剩下的2N个数满足如下规律:
最大的两个数相邻,第三第四大的两个数相邻,......,最小的两个数相邻。
直观上考虑,用数学归纳法。我们把这N(N+1)个数按从小到大排序,之后从左到右分成N组,每组N+1个数
(也即第一组是最小的N+1个数,第二组是次小的N+1个数,第N组是最大的N+1个数)。如果我们能够在
原来的序列中删去一些数,使得在剩下的数中,每一组中恰有两个,而且它们相邻,那么结论就成立了。
那么怎么删呢?贪心思想
首先从左到右扫描,找到第一对在同一组中的数,根据抽屉原理,此时至多只要扫描N+1个数。把找到的这一对数
所在的组的其余数删去,并且删去当前扫过的其他数。这个时候,由于扫过的数当中只有所选的两个数在同一组,
因此剩下的组每组至多被删除一个数。这个时候所选的两个数在最左边,右边有N-1组的数,每组的数至少N个,
对右边的数继续操作,最终就可以删去N(N-1)个数,找到2N个数满足要求。