E TLE*3 求调
  • 板块学术版
  • 楼主_ImposterX_
  • 当前回复5
  • 已保存回复5
  • 发布时间2024/5/18 22:37
  • 上次更新2024/5/19 10:30:00
查看原帖
E TLE*3 求调
921114
_ImposterX_楼主2024/5/18 22:37

大概知道要记搜,但是为啥

我感觉我爆搜复杂度没问题吧

#include <bits/stdc++.h>
#define gt getchar
#define pt putchar
#define ll int

using namespace std;

const int MAXN = 20;

ll read() {
	ll x = 0, f = 1;char ch = gt();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -1;ch = gt();}
	while (ch >= '0' && ch <= '9') {x *= 10;x += ch - '0';ch = gt();}
	return x * f;
}

ll n;
ll a[MAXN], b[MAXN];
bool f[MAXN];//第i张牌选没选过 


//1为高桥胜,0为青木胜 
inline bool dfs(ll x) {
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if(!f[i] && !f[j] && (a[i] == a[j] || b[i] == b[j])) {
				f[i] = f[j] = true;
				ll p = dfs(~ x);
				if(p == (x & 1)) {
					f[i] = f[j] = false;
					return x & 1;
				}
				f[i] = f[j] = false;
			}
		}
	}
	if(x & 1) return 0;
	return 1;
}

int main() {
	n = read();
	for (int i = 1; i <= n; i++) {
		a[i] = read(), b[i] = read();
	}
	if(dfs(1)) cout << "Takahashi\n";
	else cout << "Aoki\n";
	return 0;
}
2024/5/18 22:37
加载中...