Hakase and Nano

时间限制: 1 Sec  内存限制: 128 MB

提交: 400  解决: 104

[提交] [状态] [命题人:admin]

题目描述

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<iostream>
#include<cstdio>     //EOF,NULL
#include<cstring>    //memset
#include<cstdlib>    //rand,srand,system,itoa(int),atoi(char[]),atof(),malloc
#include<cmath>           //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
#include<algorithm>  //fill,reverse,next_permutation,__gcd,
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<iterator>
#include<iomanip>             //setw(set_min_width),setfill(char),setprecision(n),fixed,
#include<functional>
#include<map>
#include<set>
#include<limits.h>     //INT_MAX
#include<bitset> // bitset<?> n
using namespace std;

#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fori(x) for(int i=0;i<x;i++)
#define forj(x) for(int j=0;j<x;j++)
#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 int MAXN = 1e6+7;
const int maxm = 1;
const int maxn = 1000000+10;
const ll MOD = 998244353;
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;
  }
}
 

Hakase and Nano 【思维博弈】的更多相关文章

  1. upc组队赛2 Hakase and Nano【思维博弈】

    Hakase and Nano 题目描述 Hakase and Nano are playing an ancient pebble game (pebble is a kind of rock). ...

  2. HDU - 6266 - HDU 6266 Hakase and Nano (博弈论)

    题意: 有两个人从N个石子堆中拿石子,其中一个人可以拿两次,第二个人只能拿一次.最后拿完的人胜利. 思路: 类型 Hakase先 Hakase后 1 W L 1 1 W W 1 1 1 (3n) L ...

  3. HDU1079-Calendar Game 简单思维博弈··

    题意:给你1990,1.1----2001.11.4范围内的某一天,格式year month day  两人轮流操作: 1. day+1; 2.month + 1: 谁先达到2001.11.4号,谁获 ...

  4. 2017 CCPC杭州 题解

    2017CCPC杭州题目PDF Problem A. Super-palindrome 题解: 给你一个字符串,每一步可以将一个字符替换为另一个字符,问你最少多少步可以使得,该字符串任意奇数子串为回文 ...

  5. The 2017 China Collegiate Programming Contest, Hangzhou Site Solution

    A: Super_palindrome 题面:给出一个字符串,求改变最少的字符个数使得这个串所有长度为奇数的子串都是回文串 思路:显然,这个字符串肯定要改成所有奇数位相同并且所有偶数位相同 那统计一下 ...

  6. 2017CCPC杭州(ABCDJ)

    所有的题目在这里<--- 待补... Problem A. HDU6264:Super-palindrome 题意: 题目定义了一个超级回文串,这个串满足:它的任一奇数长度的串都是回文串. 现在 ...

  7. Forethought Future Cup - Final Round (Onsite Finalists Only) C. Thanos Nim 题解(博弈+思维)

    题目链接 题目大意 给你n堆石子(n为偶数),两个人玩游戏,每次选取n/2堆不为0的石子,然后从这n/2堆石子中丢掉一些石子(每一堆丢弃的石子数量可以不一样,但不能为0),若这次操作中没有n/2堆不为 ...

  8. Educational Codeforces Round 63 (Rated for Div. 2) B. Game with Telephone Numbers 博弈思维+模拟+贪心思维

    题意:博弈题面  给出一个数字序列 (>=11)  有两个人任意删除数字 直到 数字只剩下11位 如果删除后的数字串开头是8那么就是第一个赢 否则就是第二个人赢 第一个人先手  数字序列一定是奇 ...

  9. codeforces 812E Sagheer and Apple Tree(思维、nim博弈)

    codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...

随机推荐

  1. mongodb mapredReduce 多个条件分组(group by)

    from:https://my.oschina.net/chiyong/blog/289138 Mongodb 没有传统数据库的group函数,如果分组需要走MapReduce.这种MR与Hadoop ...

  2. Excel的导入导出功能

    POI组件的详细介绍文档: https://www.cnblogs.com/huajiezh/p/5467821.html .xls 对应 HSSFWorkbook book=new HSSFWork ...

  3. js函数集

    js函数集·字符串(String) 1.声明 var myString = new String("Every good boy does fine."); var myStrin ...

  4. kali长时间未使用导致数字签名过期无法更新源解决办法

    kali长时间未使用,数字签名会过期,从而导致无法更新源. apt-get update:从源(Source)服务器那里下载最新的软件包列: apt-get upgrade:对已经安装的软件包本身进行 ...

  5. GO富集分析

    GO的主要用途之一是对基因组进行富集分析.例如,给定一组在特定条件下上调的基因,富集分析将使用该基因组的注释发现哪些GO术语被过度表示(或未充分表示). 富集分析工具    用户可以直接从GOC网站的 ...

  6. python os.path.splitext()

    # Split the file extension 可以把扩展名获取出来

  7. Linux服务器---流量监控MRTG

    MRTG MRTG可以分析网络流量,但是它必须依赖SNMP协议.将收集到的数据生成HTML文件,以图片的形式展示出来 1.安装一些依赖软件 [root@localhost bandwidthd-2.0 ...

  8. pyspider源码解读--调度器scheduler.py

    pyspider源码解读--调度器scheduler.py scheduler.py首先从pyspider的根目录下找到/pyspider/scheduler/scheduler.py其中定义了四个类 ...

  9. js定时器优化

    在js中如果打算使用setInterval进行倒数,计时等功能,往往是不准确的,因为setInterval的回调函数并不是到时后立即执行,而是等系统计算资源空闲下来后才会执行.而下一次触发时间则是在s ...

  10. 51Nod 2020 排序相减

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=2020 思路:排序 水水 #include<iostre ...