当前位置: 首页 > 工具软件 > Sanguosha > 使用案例 >

hdu 4068 枚举 SanguoSHA

廖令
2023-12-01

暴力枚举。代码能力有待提高,比赛的时候老是敲错,多敲题。我要! 加油!!!Lin!!!

/*
Pro: 0

Sol:

date:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
using namespace std;
int t,n;
string people[10];
map <string , int> mp;
int a[10],b[10];
bool grid[10][10];
int main(){
    scanf("%d",&t);
    for(int ca = 1; ca <= t; ca ++){
        scanf("%d",&n);
        mp.clear();
        memset(grid,false,sizeof(grid));

        for(int i = 1; i <= n;i ++)
            cin >> people[i];
        sort(people + 1, people + 1 + n);
        for(int i = 1; i <= n; i ++)
            mp[people[i]] = i;
        for(int i = 1; i <= n; i ++){
            int k;  char name[20];
            scanf("%d",&k);
            while(k --){
                scanf("%s",name);
                grid[i][mp[name]] = true;// a can defeat b
            }
        }
        for(int i = 1; i <= n; i ++)    a[i] = i;

        bool flag ;
        do{
            //for every a sequence
            for(int j = 1; j <= n; j ++)
                b[j] = j;
            flag = true;
            do{
                int pa = 1; int pb = 1;

                while(pa <= n && pb <= n){
                    if(grid[b[pb]][a[pa]]) // b can defeat a
                        pa ++;
                    else
                        pb ++;
                }
                if(pa > n) flag = false;// i lose once, then this sequence is not the answer

            }while(next_permutation(b + 1, b + 1 + n));
            if(flag) break;//represents that a all wins

        }while(next_permutation(a + 1, a + 1 + n));

//        for(int i = n; i > 1; i --)
//            printf("%d ",a[i]); printf("%d\n",a[1]);

        printf("Case %d: ",ca);
        if(flag) {
            printf("Yes\n");
            for(int i = 1; i < n; i++)
                printf("%s ",people[a[i]].c_str());    printf("%s\n",people[a[n]].c_str());
        }else
            printf("No\n");
    }
	return 0;
}


 类似资料: