题目描述
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

题目大意是说,两个人进行抓取石子的游戏,有多个包且每个包内有一定量的石子,每次抓取至少一个石子,最后操作的人胜利,但是HaKase作弊了,每次进行两次上面的操作。问最后HaKase能否一定胜利。

博弈题最好还是先找规律。先看Hakase先手时,如果必败的话,只会出现所有袋子中只有一个石子且袋子数可以被三整除,这样HaKase拿完两个,剩下的一个被对手拿掉从而输掉比赛。所以先手的情况相对简单一些。

后手的情况下,我们不妨逆向思维,如果我是对手,我的必胜态就是HaKase的必败态,此时我的必胜态一定是只剩一个袋子,把这个袋子拿干净我就赢了,那么上一轮的情况倒着推,就是HaKase的必败态。此时共有三种情况,有一个袋子不为1且袋子数是三的倍数多一,有一个袋子不为1且袋子数是3的倍数,袋子全为1且袋子数是三的倍数多一,符合这三个条件HaKase就必败了。

AC代码

#include<iostream>
using namespace std;
int main()
{int t;cin>>t;while(t--){int x,y;cin>>x>>y;int cnt=0;for(int i=0;i<x;i++){int temp;cin>>temp;if(temp==1) cnt++;  }if(y==1){if(cnt==x&&x%3==0)cout<<"No"<<endl;elsecout<<"Yes"<<endl;}else if(y==2){if(cnt==x&&x%3==1||cnt==x-1&&x%3==1||cnt==x-1&&x%3==0)cout<<"No"<<endl;elsecout<<"Yes"<<endl;}}return 0;
}

Hakase and Nano 博弈相关推荐

  1. Hakase and Nano【博弈】

    Hakase and Nano 时间限制: 1 Sec  内存限制: 128 MB 提交: 533  解决: 155 [提交] [状态] [命题人:admin] 题目描述 Hakase and Nan ...

  2. Hakase and Nano(博弈)

    题意:有n堆石头,每堆石头有a[i]个.H和N两个人轮流拿,每人最少拿1个.1代表H先拿,2代表N先拿.问H是否会赢.H每一回合会拿两次,但是N只能拿一次. 对于H先拿的情况,如果他可以拿(代表这个堆 ...

  3. POJ1067_取石子游戏_威佐夫博弈

    /* *State: 1067 Accepted 176K 16MS C++ 435B *题目大意: * 威佐夫博弈 *解题思路: * 略. */ #include <iostream> ...

  4. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  5. jetson nano 用 tensorrt 运行 nanodet(kitti数据集)

    题目是目标,我们先一步一步来做,第一步是训练神经网络, 我用的是 kitti 数据集,训练顺序为,第一步,拿到kitti数据集,第二步,把kitti数据集修改为voc数据集格式,第三步,修改配置文件进 ...

  6. BZOJ2275[Coci2010]HRPA——斐波那契博弈

    题目描述 N个石子,A和B轮流取,A先.每个人每次最少取一个,最多不超过上一个人的个数的2倍. 取到最后一个石子的人胜出,如果A要有必胜策略,第一次他至少要取多少个. 输入 第一行给出数字N,N< ...

  7. arduino nano 蓝牙_探索 Golang 云原生游戏服务器开发,5 分钟上手 Nano 游戏服务器框架...

    介绍 Nano 是什么? 轻量级,方便,高性能 golang 的游戏服务器框架. nano 是一个轻量级的服务器框架,它最适合的应用领域是网页游戏.社交游戏.移动游戏的服务端.当然还不仅仅是游戏,用  ...

  8. 博弈最高位POJ 1704(Georgia and Bob-Nim博弈)

    新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正 Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  9. linux文本编辑nano

    2019独角兽企业重金招聘Python工程师标准>>> Nano命令指南 今天在输命令时,无意中输入了nano,对这个命令不太熟悉,结果不知道如何才能退出,保存,赶快查了一下资料,原 ...

最新文章

  1. java三种循环的区别_JavaSE三种循环注意点
  2. 云原生安全的挑战与实践
  3. Visual C++ 2010中更换MFC对话框默认图标
  4. 【Python】判断列表中是否存在一个数
  5. boost::mpl::times相关的测试程序
  6. Hybris DDIC type and its counterpart model class
  7. 超详细windows安装mongo数据库、注册为服务并添加环境变量
  8. (三)Neo4j自带northwind案例--Cypher语言应用
  9. python3的输出函数_教女朋友学Python3(二)简单的输入输出及内置函数查看 原创...
  10. 2020中国硬科技创新白皮书
  11. 计算机网络之网络层:2、IP数据报、IP数据报分片
  12. 如何修改vue打包的名字_教你如何修改Mac的电脑名字
  13. python操作之更新数据库中某个字段的数据
  14. 通过谷歌浏览器,找到页面某个事件属于哪个js文件
  15. es修改排序_ElasticSearch自定义排序(转载)
  16. oppo android多大内存,OPPO R9的内存容量是多少
  17. 基于神经网络的目标检测论文之结尾:总结与展望
  18. 软考软件评测师备考攻略
  19. dlib.get_frontal_facedetector UINT8 和float格式互相转换
  20. pixi.js v5 快速了解

热门文章

  1. POJ-2152 Fire (树形DP)
  2. 【WiFi密码破解详细图文教程】ZOL仅此一份 详细介绍从CDlinux U盘启动到设置扫描破解-破解软件论坛-ZOL中关村在线...
  3. Effective Java (7) - 避免终止方法
  4. Linux kernel进行编译时提示No rule to make target `menconfig'
  5. [导入]DotText源码阅读(2)-工程、数据库表结构
  6. 有100个GMAIL的邀请,需要的来信就可以啦。
  7. maven安装与配置等相关知识
  8. 18000 Two String 暴力。——— 读题
  9. Unity3d:Unknown type 'System.Collections.Generic.CollectionDebuggerView'1
  10. 你造吗?这个属性值你写错了多少年?target=“_blank”