拍的太慢了,很不满意

排完序之后,枚举自己和对手状态,若被击败,则再枚举自己下一个策略,直到可以击败对手所有的策略

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
int g[][];
int a1[]={,,,,,,};
int a2[]={,,,,,,};
bool check()
{
int t1=;
int t2=;
bool flag=;
while()
{
if(g[a2[t2]][a1[t1]])
{
t1++;
}
else t2++;
if(t1==n)
{
flag=;
break;
}
if(t2==n)
{
flag=;
break;
}
}
if(!flag) return ;
else return ;
}
int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
scanf("%d",&tt);
while(tt--)
{
printf("Case %d: ",ca++);
map<string,int> mp1;
map<int,string> mp2;
scanf("%d",&n);
string s[];
for(i=;i<n;i++)
{
cin>>s[i];
}
sort(s,s+n);
for(i=;i<n;i++)
{
mp1[s[i]]=i;
mp2[i]=s[i];
}
cl(g);
string sw;
for(i=;i<n;i++)
{
int num;
scanf("%d",&num);
for(j=;j<num;j++)
{
cin>>sw;
int v=mp1[sw];
g[i][v]=; //有克制关系
}
}
for(i=;i<;i++) a1[i]=i,a2[i]=i;
bool flag=;
bool w=;
while()
{
flag=;
while()
{
if(!check()) //该策略被击败
{
flag=;
}
if(!next_permutation(a2,a2+n)) break;
}
if(flag)
{
w=;
break;
}
if(!next_permutation(a1,a1+n)) break;
}
if(w)
{
printf("Yes\n");
cout<<mp2[a1[]];
for(i=;i<n;i++)
{
cout<<" "<<mp2[a1[i]];
}
printf("\n");
}
else
{
printf("No\n");
}
}
}
05-06 11:09