hdu 4068 SanguoSHA

19 篇文章 0 订阅

开始没看题,这题被大批人马虐了后我才看。。

发现规模才6.。。那就暴力被,6!*6!*6而已啦。。然后就暴力生成全排列了。。

党姐看我写,他着急 = = (一开始让他写他不写 = = ) 结果他噼里啪啦写完交1Y了 = = 我还没调完,囧。。

一个小BUG,刚才看到了,改掉顺利AC。。

直接全排列,模拟两个人对战即可。全排列打表。党用STL弄的全排列,ym啊。。。我刚也学了下那个函数。

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)

using namespace std;

const int MAX = 10;
string s[MAX];
int a[1000][MAX];
bool mm[MAX][MAX];
bool ok(int x, int y, int n)
{
	bool f[MAX];
	memset(f, true, sizeof(f));
	int l = 0, r = 0;
	while( l < n && r < n )
	{
		int xx = a[x][l], yy = a[y][r];
		if( mm[yy][xx] )
			l++;
		else
			r++;
	}
	return l < n;
}
	
int solve(int cnt, int n)
{
	FOR(i, 0, cnt)
	{
		bool f = true;
		FOR(k, 0, cnt)
			if( !ok(i, k, n) )
			{
				f = false;
				break;
			}
		if( f )
			return i;
	}
	return -1;
}
int arrMent(int n)		// 生成全排列。。呃,也就比DFS短了那么一点点吧 
{
	int cnt = 1;
	FOR(i, 0, n)
		a[0][i] = i;
	int b[MAX];
	memcpy(b, a[0], sizeof(a[0]));
	while( next_permutation(b, b+n) )
	{
		memcpy(a[cnt++], b, sizeof(b));
	}
	return cnt;
}
int main()
{
	int ncases, n, nn;
	char ss[23];	
	scanf("%d", &ncases);
	
	FOR(ind, 1, ncases+1)
	{
		scanf("%d", &n);
		FOR(i, 0, n)
		{
			scanf("%s", ss);
			s[i] = ss;
		}
		int cnt = arrMent(n);
		sort(s, s+n);
		memset(mm, false, sizeof(mm));
		FOR(i, 0, n)
		{
			scanf("%d", &nn);
			FOR(k, 0, nn)
			{
				scanf("%s", ss);
				string sss = ss;
				FOR(j, 0, n)
					if( sss == s[j] )
						mm[i][j] = true;
			}
		}
		
		int ans = solve(cnt, n);
		printf("Case %d: ", ind);
		if( ans == -1 )
			puts("No");
		else
		{
			puts("Yes");
			FOR(i, 0, n)
			{
				printf("%s", s[a[ans][i]].c_str());
				if( i != n-1 )
					printf(" ");
				else
					printf("\n");
			}
		}		
	}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值