hdu 4068 福州赛区网络赛H 排列 ***

拍的太慢了,很不满意

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

#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-5;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=1005;
int n,m,tt;
int g[15][15];
int a1[15]={0,1,2,3,4,5,6};
int a2[15]={0,1,2,3,4,5,6};
bool check()
{
    int t1=0;
    int t2=0;
    bool flag=0;
    while(1)
    {
        if(g[a2[t2]][a1[t1]])
        {
            t1++;
        }
        else t2++;
        if(t1==n)
        {
            flag=0;
            break;
        }
        if(t2==n)
        {
            flag=1;
            break;
        }
    }
    if(!flag)    return 0;
    else return 1;
}
int main()
{
    int i,j,k,ca=1;
    #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[15];
        for(i=0;i<n;i++)
        {
            cin>>s[i];
        }
        sort(s,s+n);
        for(i=0;i<n;i++)
        {
            mp1[s[i]]=i;
            mp2[i]=s[i];
        }
        cl(g);
        string sw;
        for(i=0;i<n;i++)
        {
            int num;
            scanf("%d",&num);
            for(j=0;j<num;j++)
            {
                cin>>sw;
                int v=mp1[sw];
                g[i][v]=1;  //有克制关系
            }
        }
        for(i=0;i<15;i++)    a1[i]=i,a2[i]=i;
        bool flag=1;
        bool w=0;
        while(1)
        {
            flag=1;
            while(1)
            {
                if(!check())    //该策略被击败
                {
                    flag=0;
                }
                if(!next_permutation(a2,a2+n))  break;
            }
            if(flag)
            {
                w=1;
                break;
            }
            if(!next_permutation(a1,a1+n))  break;
        }
        if(w)
        {
            printf("Yes\n");
            cout<<mp2[a1[0]];
            for(i=1;i<n;i++)
            {
                cout<<" "<<mp2[a1[i]];
            }
            printf("\n");
        }
        else
        {
            printf("No\n");
        }
    }
}
时间: 2024-11-19 18:43:14

hdu 4068 福州赛区网络赛H 排列 ***的相关文章

hdu 4068 福州赛区网络赛A 数学 ***

a1/sum 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x3f3f3

hdu 4069 福州赛区网络赛I DLC ***

再遇到一个DLC就刷个专题 1 #include <stdio.h> 2 #include <string.h> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string> 10 #in

hdu 4070 福州赛区网络赛J 贪心 ***

优先发路程最长的 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 const int INF=0x3f3

hdu 4028 2011上海赛区网络赛H dp+map离散

一开始用搜索直接超时,看题解会的 1 #include<iostream> 2 #include<cstdio> 3 #include<map> 4 #include<cstring> 5 #include<cmath> 6 #include<vector> 7 #include<queue> 8 #include<algorithm> 9 #include<set> 10 #define inf

[2018 ACM-ICPC 焦作赛区网络赛] H - String and Times(后缀自动机)

Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring wonderful substring when the times it appears in that string is between AA and BB (A \le times \le BA≤times≤B). Can you calculate the number of wonderful

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn&#39;t want to study (线段树)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a

ICPC 2018 徐州赛区网络赛

ACM-ICPC 2018 徐州赛区网络赛 ?去年博客记录过这场比赛经历:该死的水题 ?一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. ? ? D. Easy Math 题意: ? 给定 \(n\), \(m\) ,求 \(\sum _{i=1}^{m} \mu(in)\) .其中 $ 1 \le n \le 1e12$ , $ 1 \le m \le 2e9$ ,\(\mu(n)\) 为莫比乌斯函数. ? 思路: ? 容易知道,\(i\) 与 \(n\) 不互质时, \(\m

HDU 5024 (广州网络赛) Wang Xifeng&#39;s Little Plot 记忆化搜索+枚举

Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. This novel was created in Qing Dynasty, by Cao Xueqin.

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn&#39;t want to study

262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he wi