Posted on 2011-05-02 23:31
Uriel 阅读(3950)
评论(0) 编辑 收藏 引用 所属分类:
模拟 、
HDOJ
今天晚上ch_g和MEC在HDU放了场Virtual Contest, 是以前的一层HDU月赛题... 一共8道... 依然悲剧... 组队赛还是不给力啊... ...
我只过了San Guo Sha 这道, 还是最后1.5h一直纠结到最后才过...
原来一直对三国杀木有兴趣的, 所以当寝室众人沉浸其中的时候我都不参与, 结果今天这题题目没有说得很完全, 就一直纠结啊纠结... 最后QQ线上请教了会三国杀的同学才知道内奸要到最后跟主公单挑并且胜了才算赢... 题目没有提到啊... - -||
WS的代码如下...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct player {
int id;
int alive;
int nkill[4];
int sco;
} p[110];
int N, M, winner;
int n[4], idNJ;
bool killZG;
int role(char *s) {
if (!strcmp(s, "ZG"))
return 0;
if (!strcmp(s, "ZC"))
return 1;
if (!strcmp(s, "NJ"))
return 2;
if (!strcmp(s, "FZ"))
return 3;
}
void check() {
if (!n[2] && !n[3] && n[0] > 0)
winner = 1;
else if (!n[0] && !n[1] && n[2] == 1 && !n[3] && killZG)
winner = 2;
else if (!n[0])
winner = 3;
}
void getscore() {
int i, j;
if (winner == 1) {
for (i = 0; i < N; ++i) {
if (p[i].id == 0) {
p[i].sco = 4 + n[1] * 2;
p[i].sco += p[i].nkill[2] + p[i].nkill[3];
}
else if(p[i].id == 1) {
p[i].sco = 5 + n[1];
p[i].sco += p[i].nkill[2] + p[i].nkill[3];
}
else if(p[i].id == 2) {
if(killZG == false && idNJ == i)
p[i].sco = N;
}
}
}
else if(winner == 2) {
for(i = 0; i < N; ++i) {
if(p[i].id == 0) {
p[i].sco = 1;
}
else if(p[i].id == 2) {
if(p[i].alive) p[i].sco = 4 + 2 * N;
}
}
}
else if(winner == 3) {
for(i = 0; i < N; ++i) {
if(p[i].id == 2) {
if(p[i].alive) p[i].sco = 1;
}
else if(p[i].id == 3) {
p[i].sco = n[3] * 3;
p[i].sco += p[i].nkill[0] * 2;
p[i].sco += p[i].nkill[1] + p[i].nkill[2];
}
}
}
}
int main() {
int cse, i, j, a, b, r1, r2, g;
char ss[10];
scanf("%d", &cse);
while (cse--) {
scanf("%d %d", &N, &M);
memset(n, 0, sizeof(n));
killZG = false;
for (i = 0; i < N; ++i) {
scanf("%s", ss);
p[i].id = role(ss);
n[p[i].id]++;
p[i].alive = 1;
memset(p[i].nkill, 0, sizeof(p[i].nkill));
p[i].sco = 0;
}
winner = 0;
for (i = 0; i < M; ++i) {
scanf("%d %d", &a, &b);
p[b].alive = 0;
p[a].nkill[p[b].id]++;
if (!n[1] && !n[3] && (n[2] == 1)) {
if (p[a].id == 0 && p[b].id == 2) {
killZG = false;
idNJ = b;
}
else {
killZG = true;
idNJ = a;
}
}
n[p[b].id]--;
check();
if (winner!=0) {
getscore();
for (j = 0; j < N - 1; ++j) {
printf("%d ", p[j].sco);
}
printf("%d\n", p[j].sco);
break;
}
}
for (g = i + 1; g < M; ++g)
scanf("%d %d", &a, &b);
}
return 0;
}