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. redis_bj_01

    windows下安装redis 下载地址https://github.com/dmajkic/redis/downloads.下载到的Redis支持32bit和64bit.根据自己实际情况选择,我选择 ...

  2. jdk8新特性-亮瞎眼的lambda表达式

    jdk8之前,尤其是在写GUI程序的事件监听的时候,各种的匿名内部类,大把大把拖沓的代码,程序毫无美感可言!既然Java中一切皆为对象,那么,就类似于某些动态语言一样,函数也可以当成是对象啊!代码块也 ...

  3. SQL 跟据出生日期求年龄

    最近做项目时遇到一个问题. 跟据人员的生日与当前日期进行比较求出该人员实际年龄.这个看上去比较简单的问题,其实不细心去看也会有很多问题. 先看第一种: 一张人员信息表里有一人生日(Birthday)列 ...

  4. tr字符串的梗

    工作问题总结 声明:应用程序代码为前人所写,仅仅只是维护代码,暂且不论代码风格瑕疵. 结论: 使用tr“包”起来的字符串,可能会被翻译为不同的语言,此时,应用程序在不同语言环境下可能会表现BUG. 1 ...

  5. Linux中常用的50个命令

    1. [命令]:cat [功能说明]: concatenate files and print on the standard output #连接文件并打印到标准输出,有标准输出的都可以用重定向定向 ...

  6. ATM取款机

    package Tests; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;impo ...

  7. kali 开启ssh服务

    1.    一.配置SSH参数 修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉,并且将NO修 ...

  8. 排名函数——ROW_NUMBER()、RANK()、DENSE_RANK()和NTILE(n)

    ROW_NUMBER()函数:行号,根据作为参数传递给这个函数的ORDER BY子句的值,返回一个不断递增的整数值.如果ROW_NUMBER的ORDER BY的值和结果集中的顺序相匹配,返回值将是递增 ...

  9. activemq消息队列的使用及应用docker部署常见问题及注意事项

    activemq消息队列的使用及应用docker部署常见问题及注意事项 docker用https://hub.docker.com/r/rmohr/activemq/配置在/data/docker/a ...

  10. Codeforce 791A - Bear and Big Brother

    Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. ...