首页 > 其他分享 >Poi2004

Poi2004

时间:2024-04-03 16:44:41浏览次数:18  
标签:return cout int Poi2004 long sg define

博弈论 #阶梯博弈

对于每一个 \(a_i\) ,转化为它到 \(m-2\) 的间隔数,然后发现这个等价于阶梯博弈

阶梯博弈只考虑奇数位,但是同时也要考虑操作完偶数位以后是必败状态的情况

注意如果一开始在 \(m-2\) 上有数,那么必胜一定是先取这些数

// Author: xiaruize
#ifndef ONLINE_JUDGE
bool start_of_memory_use;
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
clock_t start_clock = clock();
#endif
#define int long long
#define ull unsigned long long
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pis pair<int, string>
#define sec second
#define fir first
#define sz(a) int((a).size())
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define rep(i, a, n) for (int i = (a); i <= (n); ++i)
#define per(i, n, a) for (int i = (n); i >= (a); --i)
int max(int a, int b)
{
	if (a > b)
		return a;
	return b;
}
int min(int a, int b)
{
	if (a < b)
		return a;
	return b;
}
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int N = 1e6 + 10;

int n, m;
int a[N], sg[N << 2], tot;

void solve()
{
	cin >> m >> n;
	rep(i, 1, n) cin >> a[i];
	if (a[n] == m - 1)
	{
		int res = 0;
		rep(i, 1, n) res += (a[i] == m - n + i - 1);
		cout << res << endl;
		return;
	}
	a[n + 1] = m - 1;
	per(i, n, 1)
	{
		if (a[i] == a[i + 1] - 1)
			sg[tot]++;
		else if (a[i] == a[i + 1] - 2)
			sg[++tot]++;
		else if ((a[i + 1] - a[i]) & 1)
			sg[tot += 2]++;
		else
			sg[tot += 3]++;
	}
	int cur = 0;
	for (int i = 1; i <= tot; i += 2)
		cur ^= sg[i];
	if (!cur)
	{
		cout << "0" << endl;
		return;
	}
	int res = 0;
	for (int i = 1; i <= tot; i += 2)
	{
		if ((sg[i] ^ cur) < sg[i])
			res++;
		if (i != tot && (sg[i] ^ cur) > sg[i] && sg[i + 1] >= (sg[i] ^ cur) - sg[i])
			res++;
	}
	cout << res << endl;
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int testcase = 1;
	// cin >> testcase;
	while (testcase--)
		solve();
#ifndef ONLINE_JUDGE
	cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
	cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
	return 0;
}

标签:return,cout,int,Poi2004,long,sg,define
From: https://www.cnblogs.com/xiaruize/p/18113027

相关文章

  • luogu P1543 [POI2004] SZP 题解
    题目传送门前置知识树形DP解法将\(a_{i}\)向\(i\)连一条有向边,这样就形成了基环外向树森林。基环外向树森林内每棵基环外向树是相互独立的,需要单独处理。对于每棵基环外向树,任取环上一点\(x\),断开\(x\)到\(fa_{x}\)的有向边,外向树就变成了一棵以\(x\)为根的树。......
  • [POI2004] SZP
    [POI2004]SZP题目描述:Byteotian中央情报局(BIA)雇佣了许多特工。他们每个人的工作就是监视另一名特工。Byteasar国王需要进行一次秘密行动,所以他要挑选尽量多的信得过的特工。但是这项任务是如此的机密以至于所有参加行动的特工都必须至少被另一名没有参加任务的特工所监视(就是......
  • [POI2004] Gra
    前言:谁知道我是怎么看教练的bug代码AC而怀疑人生的。已经研究困了。思路:题目传送门博弈论最重要的是,发现模型并进行转模。这题很容易发现,与阶梯模型十分相似。可以考虑每个棋子距离\(M\)还有多少空格转化成当前在第几级阶梯。可是当我们转化后发现,胜利条件有一些不一样......
  • P5911 [POI2004]PRZ
    PRZ——PixelRebelz(?传送门哈哈!思路预处理$T_i$以及$W_i$,为状态为$i$时不分组直接过(管他压不压断桥)的时间和总重量。然后$f_i$就是过桥状态为$i......
  • P5914 [POI2004]MOS 题解
    题目传送门分析这是一道小学经典的数学题,对于这种求最短时间的题目,我们要认真考虑两组人员:首先,跑的快的人应当跑的最多,能者多劳。其次,跑的慢的人应当跑的最少,否则会拉......
  • P5911 [POI2004]PRZ——状压dp
    一样,从\(n\le16\)启发用状压dp思路本质上与UVA11825Hackers'Crackdown异曲同工,不过可以通过预处理处理出一组人的集合时间复杂度最坏为\(O(2^{2n})\),当任何一个集合......