upc组队赛2 Hakase and Nano【思维博弈】
Hakase and Nano
题目描述
Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). There are n packs of pebbles, and the i-th pack contains ai pebbles. They take turns to pick up pebbles. In each turn, they can choose a pack arbitrarily and pick up at least one pebble in this pack. The person who takes the last pebble wins.
This time, Hakase cheats. In each turn, she must pick pebbles following the rules twice continuously.
Suppose both players play optimally, can you tell whether Hakase will win?
输入
The first line contains an integer T (1≤T≤20) representing the number of test cases.
For each test case, the fi rst line of description contains two integers n(1≤n≤106) and d (d = 1 or d = 2). If d = 1, Hakase takes first and if d = 2, Nano takes first. n represents the number of pebble packs.
The second line contains n integers, the i-th integer ai (1≤ai≤109) represents the number of pebbles in the i-th pebble pack.
输出
For each test case, print “Yes” or “No” in one line. If Hakase can win, print “Yes”, otherwise, print “No”.
样例输入
2
3 1
1 1 2
3 2
1 1 2
样例输出
Yes
No
题解
以为是NIM,一直在想怎么控制数量相同,然后自己写了几组数据找规律发现总是能赢..
就去找会输的情况,发现只有很多1的时候才会输
先手的话只有全部是1,并且堆数得是3的倍数才会输
后手就是在先手的情况下加一步,
有一堆数量不为1的堆,其他全部为1 并且堆数得是3的倍数
或者 ,堆数得是3的倍数 + 1 ,有一堆的数量任意,其他全为1
代码
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(y))
#define all(x) x.begin(),x.end()
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long LL;
typedef long long ll;
const double eps=1e-8;
const double PI = acos(1.0);
const int INF = 0x3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll mod = 998244353;
const int MAXN = 1e6+7;
const int maxm = 1;
const int maxn = 100000+10;
int T;
ll a[maxn];
int flag ;
int n,d;
int cnt ;
int main(){
read(T);
while(T--){
read2(n,d);
cnt = 0;
for(int i = 0; i < n; i++){
scanf("%lld",&a[i]);
if(a[i] != 1) cnt ++;
}
flag = 1;
if(d == 1){
if(n % 3 == 0 && cnt == 0) flag = 0;
}
if(d == 2) {
if(n % 3 == 0 && cnt == 1) flag = 0;
else if(n % 3 == 1 && cnt <= 1) flag = 0;
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
upc组队赛2 Hakase and Nano【思维博弈】的更多相关文章
- upc组队赛5 Assembly Required【思维】
Assembly Required 题目描述 Princess Lucy broke her old reading lamp, and needs a new one. The castle ord ...
- Hakase and Nano 【思维博弈】
Hakase and Nano 时间限制: 1 Sec 内存限制: 128 MB 提交: 400 解决: 104 [提交] [状态] [命题人:admin] 题目描述 Hakase and Nan ...
- HDU - 6266 - HDU 6266 Hakase and Nano (博弈论)
题意: 有两个人从N个石子堆中拿石子,其中一个人可以拿两次,第二个人只能拿一次.最后拿完的人胜利. 思路: 类型 Hakase先 Hakase后 1 W L 1 1 W W 1 1 1 (3n) L ...
- upc组队赛3 Chaarshanbegaan at Cafebazaar
Chaarshanbegaan at Cafebazaar 题目链接 http://icpc.upc.edu.cn/problem.php?cid=1618&pid=1 题目描述 Chaars ...
- upc组队赛2 Master of GCD 【线段树区间更新 || 差分】
Master of GCD 题目描述 Hakase has n numbers in a line. At fi rst, they are all equal to 1. Besides, Haka ...
- upc组队赛1 过分的谜题【找规律】
过分的谜题 题目描述 2060年是云南中医学院的百年校庆,于是学生会的同学们搞了一个连续猜谜活动:共有10个谜题,现在告诉所有人第一个谜题,每个谜题的答案就是下一个谜题的线索....成功破解最后一个谜 ...
- upc组队赛1 不存在的泳池【GCD】
不存在的泳池 题目描述 小w是云南中医学院的同学,有一天他看到了学校的百度百科介绍: 截止到2014年5月,云南中医学院图书馆纸本藏书74.8457万册,纸质期刊388种,馆藏线装古籍图书1.8万册, ...
- upc组队赛1 黑暗意志【stl-map】
黑暗意志 题目描述 在数千年前潘达利亚从卡利姆多分离之时,迷雾笼罩着这块新形成的大陆,使它不被外来者发现.迷雾同样遮蔽着这片大陆古老邪恶的要塞--雷神的雷电王座.在雷神统治时期,他的要塞就是雷电之王力 ...
- upc组队赛1 闪闪发光 【优先队列】
闪闪发光 题目描述 一所位于云南昆明的中医药本科院校--云南中医学院. 因为报考某专业的人数骤减,正面临着停招的危机. 其中有九名少女想到一条妙计--成为偶像, 只要她们成为偶像,学校的名气便会增加, ...
随机推荐
- T1218:取石子游戏
[题目描述] 有两堆石子,两个人轮流去取.每次取的时候,只能从较多的那堆石子里取,并且取的数目必须是较少的那堆石子数目的整数倍,最后谁能够把一堆石子取空谁就算赢. 比如初始的时候两堆石子的数目是25和 ...
- 带有headers的urllib库爬取
#请求头 #1.引入模块 from urllib import request #2.操作 #(1)定义目标url base_url = "http://www.langlang2017.c ...
- 一些关于SEO优化的笔记
高级搜索指令: 双引号:“xxx” 代表完全匹配的搜索 减号:-(减号前面必须是空格,后面必须没有空格)代表搜索不包含减号后面的词的页面 filetype:用于搜索特定文件格式(百度支持的文件类型:P ...
- python-前端Jquery
Jquery 高级版javascript 提供了更加便利的js使用方式 楔子 需求二:将上面的li标签实现隔行换色效果 js代码 <script> var obj = document.g ...
- JS原型与原型链终极详解 (转载)
这篇文章需要认认真真仔仔细细的看才能看懂 一. 普通对象与函数对象 JavaScript 中,万物皆对象!但对象也是有区别的.分为普通对象和函数对象,Object ,Function 是JS自带的函 ...
- leetcode.图.785判断二分图-Java
1. 具体题目 给定一个无向图graph,当这个图为二分图时返回true.如果我们能将一个图的节点集合分割成两个独立的子集A和B,并使图中的每一条边的两个节点一个来自A集合,一个来自B集合,我们就将这 ...
- HDU 3406 Baseball of Planet Pandora
Baseball of Planet Pandora Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 【转】modulenotfounderror: no module named 'matplotlib._path'问题的解决
今天在装matplotlib包的时候遇到这样的问题,在网上找了很长时间没有类似很好的解决方法,最后自己 研究找到了解决的方法. 之前在pycharm里面已经装了matplotlib包,之后觉着下载包挺 ...
- Centos,tomcat
1.下载tomcat9.0,解压,配置 wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.21/bin/apa ...
- LAN VLAN与VXLAN学习笔记
一.LAN(Local Area Network,局域网) 1.通信方式: 向目标IP地址发送ARP广播,获取目的IP地址的MAC地址,然后用单播MAC地址实现相互通信 2.LAN的特点: 1.同一L ...