1040: 二哥的困惑 Ⅲ
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 208 Solved: 80
[ Submit][ Status][ Web Board]
Description
Suppose there are M people, including you, playing a special card game. At the beginning, each player receives N cards. The pip of a card is a positive integer which is at most N*M. And there are no two cards with the same pip. During a round, each player chooses one card to compare with others. The player whose card with the biggest pip wins the round, and then the next round begins. After N rounds, when all the cards of each player have been chosen, the player who has won the most rounds is the winner of the game.
Given your cards received at the beginning, write a program to tell the maximal number of rounds that you may at least win during the whole game.
Input
The input consists of several test cases. The first line of each case contains two integers m (2<=m<=20) and n(1<=n<=50), representing the number of players and the number of cards each player receives at the beginning of the game, respectively. This followed by a line with n positive integers, representing the pips of cards you received at the beginning. Then a blank line follows to separate the cases.
The input is terminated by a line with two zeros.
Output
For each test case, output a line consisting of the test case number followed by the number of rounds you will at least win during the game.
Sample Input
Sample Output
HINT
Source
给定n*m的数字,你有其中n个,进行n轮出数字,数字大的赢,求你至少能赢的轮数。
可以这样考虑,因为是至少,所以可按从大到小顺序出,如果其他人的数字没有当前最大的大,那么其他人不出大的。
#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define pi acos(-1)
int main() {
int m, n, a[1005], b[1005], t = 0;
bool flag[1005];
while (~scanf("%d%d", &m, &n)) {
if (m == 0 && n == 0) {
break;
}
t++;
memset(flag, false, sizeof(flag));
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
flag[a[i]] = true;
}
sort(a, a + n);
int s = 0;
for (int i = 1; i <= n * m; ++i) {
if (!flag[i]) {
b[s++] = i;
}
}
int l = 0, ans = 0;
s--, n--;
while (n >= 0) {
if (a[n] > b[s]) {
ans++;
}
else {
s--;
}
n--;
}
printf("Case %d: ", t);
cout << ans << endl;
}
return 0;
}