题目大意:
一种牌类游戏,模拟。
不想说了,自己看题吧。
#include <stdio.h>
#include <math.h>
#include <memory.h>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int MAXN = 210;
int player[MAXN][15], n, m;
int card[20005],start;
int Next[14] = {0, 2, -1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};
int Min(int *p) {
for (int i = 3; i <= 13; i++)
if(p[i])return i;
if(p[1])return 1;
if(p[2])return 2;
}
bool judge(int *p) {
for (int i = 1; i <= 13; i++)
if (p[i]) return false;
return true;
}
void print(int id) {
printf("Case #%d:\n", id);
for (int i = 1; i <= n; i++) {
int sum = 0;
for (int j = 1; j <= 13; j++) {
sum += j * player[i][j];
}
if (sum) printf("%d\n", sum);
else printf("Winner\n");
}
}
int main () {
int T;
scanf("%d", &T);
for (int k = 1; k <= T; k++)
{
memset(player, 0, sizeof(player));
memset(card, 0, sizeof(card));
start=0;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &card[i]);
}
for (int i = 1; i <= n&&start<m; i++)
for (int j = 0; j < 5&&start<m; j++){
player[i][card[start++]] ++;
}
int p = 2, cur = Min(player[1]), next, last = 1;
player[1][cur] --;
//printf("%d号玩家出%d:\n",1,cur);
while (1) {
if (last != p) {
next = Next[cur];
if (next!=-1&&player[p][next]) {
player[p][next] --;
//printf("%d号玩家出%d:\n",p,next);
cur = next;
last = p;
if (judge(player[p]))
break;
}
else if (player[p][2] && cur != 2) {
player[p][2] --;
//printf("%d号玩家出%d:\n",p,2);
cur = 2;
last = p;
if (judge(player[p]))
break;
}
p = p % n + 1;
}
else {
if(start<m)
{
int temp = card[start++];
player[last][temp] ++;
//printf("%d号玩家摸%d:\n",last,temp);
if(start<m)
{
int t = last % n + 1;
while(t != last&&start!=m)
{
int temp = card[start++];
player[t][temp] ++;
//printf("%d号玩家摸%d:\n",t,temp);
t = t % n + 1;
}
}
}
cur = Min(player[last]);
player[last][cur] --;
//printf("%d号玩家出%d:\n",last,cur);
if (judge(player[last])) break;
p = p % n + 1;
}
}
print(k);
}
}