题意:给定一个数组,要求Alice和Bob两个人一前一后的选择数并删除,Alice能否选出偶数总和的数以获得胜利。

思路:Alice选偶数时,Bob总是也选偶数留下奇数使得Alice的数字改变奇偶性,Alice选奇数时,Bob总是也选奇数使得Alice选偶数不改变她的奇偶性。

于是我们把奇偶分开来看,对于奇数的数量,做分类讨论

cnt1%4==0,Alice胜

cnt1%4==1,此时cnt2&1,Bob胜,因为剩下一个奇数Alice选,反之Alice胜

cnt1%4==2,此时Bob必胜,因为最后两个奇数一人一个

cnt1%4==3,Alice必胜,因为Alice最后拿两个奇数

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>//#define int ll
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 1000010, M = 2 * N, B = N, MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;//int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int dx[8] = { 1,2,2,1,-1,-2,-2,-1 }, dy[8] = { 2,1,-1,-2,-2,-1,1,2 };
int n;
int a[N];
bool dp[110][110];ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll MOD) {ll res = 1;while (b) {if (b & 1) res = res * a % MOD;a = a * a % MOD;b >>= 1;}return res;
}inline void init() {}void slove()
{cin >> n;pre(i, 1, n) cin >> a[i];int cnt1 = 0, cnt2 = 0;pre(i, 1, n){if (a[i] & 1) cnt1++;else cnt2++;}if (cnt1 % 4 == 0)puts("Alice");else if (cnt1 % 4 == 1){if (n & 1)puts("Bob");else puts("Alice");}else if (cnt1 % 4 == 2)puts("Bob");else if (cnt1 % 4 == 3)puts("Alice");return;
}signed main()
{//IOS;int _ = 1;si(_);init();while (_--){slove();}return 0;
}
/*
1
3 15
1 9
1 9
1 8*/

dp做法

显然,该题的胜负只与奇数和偶数的数量有关,因此,我们做关于奇数和偶数的dp

用odd,even两个二维数组保存当奇数偶数分别为i,j时,先手能否一定取到奇数或者偶数。

哎,这时候就有人要问了,不是只要求能否取到偶数吗,为什么还要有奇数呢?

我们来看看推导过程,首先,当我们从ij向之前的状态转移时,于是我们要的答案变成cntodd&1==1时,even[i][j-1],even[i-1][j]均为false,cntodd&1==0时odd[i-1][j],odd[i][j-1]均为false,所以需要odd辅助,同时,我们也需要维护odd数组

还有需要注意的边界问题(i==0||j==0)

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>//#define int ll
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 1000010, M = 2 * N, B = N, MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;//int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int dx[8] = { 1,2,2,1,-1,-2,-2,-1 }, dy[8] = { 2,1,-1,-2,-2,-1,1,2 };
int n;
int a[N];
bool even[110][110];
bool odd[110][110];ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll MOD) {ll res = 1;while (b) {if (b & 1) res = res * a % MOD;a = a * a % MOD;b >>= 1;}return res;
}inline void init() {/*for (int i = 1; i <= 100; i++){even[i][0] = (i + 1) / 2 & 1 ^ 1;even[0][i] = 1;odd[i][0] = (i + 1) / 2 & 1;odd[0][i] = 0;}*/even[0][1] = true, even[1][0] = false;odd[1][0] = true, odd[0][1] = false;for(int cnt=2;cnt<=100;cnt++)for (int i = 0; i <= cnt; i++) {int j = cnt - i;if (i & 1){if(i) even[i][j] |= !even[i - 1][j];if(j) even[i][j] |= !even[i][j - 1];if(i) odd[i][j] |= !odd[i - 1][j];if(j) odd[i][j] |= !odd[i][j - 1];}else{if(i) even[i][j] |= !odd[i - 1][j];if(j) even[i][j] |= !odd[i][j - 1];if(i) odd[i][j] |= !even[i - 1][j];if(j) odd[i][j] |= !even[i][j - 1];}}
}void slove()
{cin >> n;pre(i, 1, n) cin >> a[i];int cnt1 = 0, cnt2 = 0;pre(i, 1, n){if (a[i] & 1) cnt1++;else cnt2++;}if (even[cnt1][cnt2])puts("Alice");else puts("Bob");
}signed main()
{//IOS;int _ = 1;si(_);init();while (_--){slove();}return 0;
}
/*
1
3 15
1 9
1 9
1 8*/

这是1500的博弈题?,这就叫惊喜!

Codeforces C. Even Number Addicts相关推荐

  1. CodeForces 991E Bus Number DFS+ 组合数

    CodeForces 991E Bus Number DFS+ 组合数 题目大意:给定一个数字,数字里出现的每一个数,都至少要用一个,问能组成多少个新数,不加前导零. input: 2028 outp ...

  2. Codeforces 40 E. Number Table

    题目链接:http://codeforces.com/problemset/problem/40/E 妙啊... 因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的, ...

  3. 第11期《codeforces 1167A - Telephone Number 题解 》

    题目描述如下: A. Telephone Number time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. Codeforces 55D Beautiful Number (数位统计)

    把数位dp写成记忆化搜索的形式,方法很赞,代码量少了很多. 下面为转载内容:  a positive integer number is beautiful if and only if it is  ...

  5. 【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

    题干: Given the number n, find the smallest positive integer which has exactly n divisors. It is guara ...

  6. C. Even Number Addicts

    Problem - C - Codeforces 题意是给你一串序列,每个人轮流,如果Alice最后的总和是偶数就赢,不然Alice最后的总和是奇数就输,Bob就赢,问最后谁赢了 博弈论 我感觉博弈论 ...

  7. codeforces 124A The number of positions

    点击打开链接 A. The number of positions time limit per test 0.5 second memory limit per test 256 megabytes ...

  8. Codeforces 1499D - The Number of Pairs(数论 + 组合计数)

    昨晚的cf没打,然后有人QQ问我D来着,正好在上毛概课可以划水就来口胡一波题解( 较为简单的套路题 ? (逃 简单实现一下就行了 ~ #include <bits/stdc++.h>usi ...

  9. Codeforces 991E. Bus Number (DFS+排列组合)

    解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...

  10. Codeforces 1430 A. Number of Apartments

    Recently a new building with a new layout was constructed in Monocarp's hometown. According to this ...

最新文章

  1. c语言单链表需要头结点,一个关于C语言链表头结点的问题
  2. 如何禁止使用本地administrator进行共享连接
  3. 利用js对页面数据进行排序
  4. 升技主板RAID磁盘阵列图解
  5. windows 7下如何卸载重装mysql 压缩包版百度经验_windows下安装、卸载mysql服务的方法(mysql 5.6 zip解压...
  6. boost::math模块查找正态(高斯)尺度(标准差)的示例的测试程序
  7. 关于setTimeout和setInterval的函数参数问题
  8. linux 进程通信子mmap
  9. 一文看懂 | 内存交换机制
  10. oracle数据库启动
  11. js提交java后台,双引号转义为amp;quot;解决办法……StringEscapeUtils.unescapeHtml4完美解决
  12. c iostream.源码_通达信指标公式源码精准买卖主图指标公式免费分享
  13. Mysql数据库——数据表的优化、外键与三范式
  14. [转载]如何限制一个类对象只在栈(堆)上分配空间?
  15. maven的一些依赖
  16. Groovy模板引擎
  17. phpcms站点域名配置https无法提交如何处理
  18. 5G物联网网络相关等专有名词解析-持续更新中
  19. Endless Dice 游戏解析
  20. 使用IDEA写程序时,运行忽然报错,提示:在类*** 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)

热门文章

  1. 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
  2. ubuntu 20安装NVIDIA驱动并处理蓝色背景的界面 perform mok management
  3. 关于微信公众号,无法接受服务器消息的原因
  4. 空集有四种写法,你知道么?——常用Latex符号表来啦!
  5. JSK-布设光钎-Kruscal最小生成树-并查集-图的连通性
  6. 蜂巢APP启动优化实践
  7. 推动铅蓄电池绿色“转身”
  8. 通州区机器人比赛活动总结_机器人大赛总结报告
  9. 【bfs 反向建边】2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16) Jumping
  10. Ubuntu终端中字体颜色含义