在比赛的时候和小昱一起做的,他20min做出来了,而我却花了两个多小时啊!!他还是学弟呢= =内心无比歉疚...
因为有些东西很不熟练吧!!虽然我想出暴力的方法还是很快很快的... 编码那个速度哦...
#include<iostream>
#include<algorithm>
#include<map>
#include<string.h>
using namespace std;bool cmp( string a,string b ){ return a<b; }int main()
{int T;cin>>T;int k;map< string,int > f;string myhero[7];string ophero[7];string relation[7][7];int length[7];for( k=1;k<=T;k++ ){f.clear();int N;int i,j;cin>>N;for( i=1;i<=N;i++ ){ cin>>myhero[i];ophero[i]=myhero[i];f[myhero[i]]=i;}for( i=1;i<=N;i++ ){cin>>length[i];for( j=1;j<=length[i];j++ )cin>>relation[i][j];}//---------------------------------------sort( myhero+1,myhero+1+N,cmp );bool yes=false;int C[7]={1,1,2,6,24,120,720};for( i=1;i<=C[N];i++ ){for( j=1;j<=C[N];j++ ){int ia=1,ib=1;while( ia<=N&&ib<=N ){int p;bool win=true;for( p=1;p<=length[ f[ophero[ib]] ];p++ )if( relation[ f[ophero[ib]] ][p]==myhero[ia] ){win=false;break;}if( win )ib++;else ia++;}next_permutation(ophero+1,ophero+1+N);if( ia>N )goto Con;}Con:if( j>C[N] ){yes=true;break;}next_permutation(myhero+1,myhero+1+N);}if( yes ){cout<<"Case "<<k<<": Yes\n";cout<<myhero[1];for(i=2;i<=N;i++ )cout<<" "<<myhero[i];cout<<endl;}elsecout<<"Case "<<k<<": No"<<endl;}return 0;
}