HDU **** 暴力類比

來源:互聯網
上載者:User

在比賽的時候和小昱一起做的,他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;         }         else             cout<<"Case "<<k<<": No"<<endl;    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.