「NOIP2015」斗地主

传送门
Luogu

解题思路

给你们一张搜索顺序图,然后就大力模拟就好。

细节注意事项

  • 爆搜题,你们懂的。。。

参考代码

写的有点丑了,洛谷上只能过加强版的88分,会T六个点

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
	s = 0; int f = 0; char c = getchar();
	while (!isdigit(c)) f |= c == '-', c = getchar();
	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
	s = f ? -s : s;
}

int n, ans, sum[25];

inline void dfs(int x) {
	if (x >= ans) return;
	int cnt = 0;
	for (rg int i = 3; i <= 14; ++i) {
		if (sum[i] < 1) cnt = 0;
		else if ((++cnt) >= 5) {
			for (rg int j = i - cnt + 1; j <= i; ++j) --sum[j];
			dfs(x + 1);
			for (rg int j = i - cnt + 1; j <= i; ++j) ++sum[j];
		}
	}
	cnt = 0;
	for (rg int i = 3; i <= 14; ++i) {
		if (sum[i] < 2) cnt = 0;
		else if ((++cnt) >= 3) {
			for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 2;
			dfs(x + 1);
			for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 2;
		}
	}
	cnt = 0;
	for (rg int i = 3; i <= 14; ++i) {
		if (sum[i] < 3) cnt = 0;
		else if ((++cnt) >= 2) {
			for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] -= 3;
			dfs(x + 1);
			for (rg int j = i - cnt + 1; j <= i; ++j) sum[j] += 3;
		}
	}
	for (rg int i = 2; i <= 14; ++i) {
		if (sum[i] >= 3) {
			sum[i] -= 3;
			for (rg int j = 2; j <= 15; ++j) {
				if (i == j || sum[j] < 1) continue;
				--sum[j], dfs(x + 1), ++sum[j];
			}
			for (rg int j = 2; j <= 14; ++j) {
				if (i == j || sum[j] < 2) continue;
				sum[j] -= 2, dfs(x + 1), sum[j] += 2;
			}
			sum[i] += 3;
		}
		if (sum[i] >= 4) {
			sum[i] -= 4;
			for (rg int j = 2; j <= 15; ++j) {
				if (i == j || sum[j] < 1) continue;
				--sum[j];
				for (rg int k = 2; k <= 15; ++k) {
					if (i == k || sum[k] < 1) continue;
					--sum[k], dfs(x + 1), ++sum[k];
				}
				++sum[j];
			}
			for (rg int j = 2; j <= 14; ++j) {
				if (i == j || sum[j] < 2) continue;
				sum[j] -= 2;
				for (rg int k = 2; k <= 14; ++k) {
					if (i == k || sum[k] < 2) continue;
					sum[k] -= 2, dfs(x + 1), sum[k] += 2;
				}
				sum[j] += 2;
			}
			sum[i] += 4;
		}
	}
	for (rg int i = 2; i <= 15; ++i) x += sum[i] > 0;
	ans = min(ans, x);
}

inline void solve() {
	memset(sum, 0, sizeof sum);
	for (rg int i = 1; i <= n; ++i) {
		int x, y; read(x), read(y);
		if (x == 0) ++sum[15];
		else if (x == 1) ++sum[14];
		else ++sum[x];
	}
	ans = 2147483647, dfs(0);
	printf("%d\n", ans);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
#endif
	int T; read(T), read(n);
	while (T--) solve();
	return 0;
}

完结撒花 \(qwq\)

posted @ 2019-10-28 20:22  Sangber  阅读(137)  评论(0编辑  收藏  举报