SanguoSHA
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 854 Accepted Submission(s): 477
Problem Description
Sanguosha has a singled version. Two players each select N heroes and start fighting. If a hero dies, the next follows. If one player's heroes are all dead, he loses.
There're restraints among heroes. For example, YuJi restricts Zhu Geliang, LuXun restricts DaQiao, ZhangJiao restricts MaChao, WeiYan restricts XiaoQiao.
Today I play with friends. I know the heroes and the restraints.(If opponent's hero restraint my hero, my hero will be beaten, others my hero will beat opponent's hero)
Can you arrange my heroes' order,no matter what order of opponent's heroes, so that I can win the game?
There're restraints among heroes. For example, YuJi restricts Zhu Geliang, LuXun restricts DaQiao, ZhangJiao restricts MaChao, WeiYan restricts XiaoQiao.
Today I play with friends. I know the heroes and the restraints.(If opponent's hero restraint my hero, my hero will be beaten, others my hero will beat opponent's hero)
Can you arrange my heroes' order,no matter what order of opponent's heroes, so that I can win the game?
Input
The first line is a number T(1<=T<=50), represents the number of case. The next T blocks follow each indicates a case.
The first line is N(3<=N<=6).
The second line has N names(shorter than 20 letter).
The following N lines each contains a restraints. Restraints are given as “k b1 b2 … bk”, which means the opponent's hero restricts my hero b1, b2 … bk. (0<=K<=N)
The first line is N(3<=N<=6).
The second line has N names(shorter than 20 letter).
The following N lines each contains a restraints. Restraints are given as “k b1 b2 … bk”, which means the opponent's hero restricts my hero b1, b2 … bk. (0<=K<=N)
Output
For each case, first line output the number of case with "Yes" or "No". If Yes, output the order of your heroes separate by a space. If there are more than one order, please output the one with minimum lexicographic order.(as shown in the sample output)
Sample Input
2 3 ZhugeLiang HuangYueying ZhenJi 1 ZhugeLiang 2 HuangYueying ZhenJi 2 ZhugeLiang ZhenJi 4 MaChao YanLiangWenChou YuJin XiaoQiao 2 MaChao XiaoQiao 2 YanLiangWenChou YuJin 1 XiaoQiao 0
Sample Output
Case 1: No Case 2: Yes MaChao YanLiangWenChou XiaoQiao YuJin
思路:就是全排列暴力枚举。
AC代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
char s1[7][100],s2[7][100],s3[100];
map<string,int> match;
int T,t,n,vis[10],hero[10][10],num[10],num2[1000][10],len;
bool flag,flag2;
void init()
{ int i,j,k,pos;
memset(vis,0,sizeof(vis));
for(i=1;i<=n;i++)
s2[i][0]='\0';
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++)
{ if(vis[j]==0)
{ pos=j;
for(k=1;k<=n;k++)
if(vis[k]==0 && k!=pos)
if(strcmp(s1[pos],s1[k])==1)
pos=k;
vis[pos]=1;
strcat(s2[i],s1[pos]);
break;
}
}
}
}
bool sha(int a,int b)
{ int i=1,j=1,k;
while(i<=n && j<=n)
{ if(hero[num2[a][i]][num2[b][j]]==1)
j++;
else
i++;
}
return i>n;
}
void jia()
{ len++;
for(int i=1;i<=n;i++)
num2[len][i]=num[i];
}
void pai(int pos)
{ if(pos==n+1)
jia();
int i,j,k;
for(i=1;i<=n;i++)
if(vis[i]==0)
{ num[pos]=i;
vis[i]=1;
pai(pos+1);
vis[i]=0;
}
}
int main()
{ int m,i,j,k,pos;
scanf("%d",&T);
for(t=1;t<=T;t++)
{ scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%s",s1[i]);
init();
match.clear();
for(i=1;i<=n;i++)
match[s2[i]]=i;
memset(hero,0,sizeof(hero));
for(i=1;i<=n;i++)
{ scanf("%d",&m);
while(m--)
{ scanf("%s",s3);
hero[i][match[s3]]=1;
}
}
memset(vis,0,sizeof(vis));
flag=false;
len=0;
pai(1);
for(i=1;i<=len;i++)
{ if(flag)
break;
flag2=true;
for(j=1;j<=len;j++)
{ if(!sha(j,i))
flag2=false;
}
if(flag2)
{ flag=true;
pos=i;
}
}
if(flag==false)
printf("Case %d: No\n",t);
else
{ printf("Case %d: Yes\n",t);
printf("%s",s2[num2[pos][1]]);
for(i=2;i<=n;i++)
printf(" %s",s2[num2[pos][i]]);
printf("\n");
}
}
}
三国杀英雄排序策略

本文介绍了一种在游戏《三国杀》中确保胜利的策略,通过全排列暴力枚举找到字典序最小的方法,使玩家不论对手如何排列都能获胜。
618

被折叠的 条评论
为什么被折叠?



