备战省赛第二场 问题 C: Hakase and Nano

 

[提交] [状态] [命题人: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

题意是博士一次取两个,另一个人一次一个

模拟模拟找找规律

 

如果先手的话博士输的概率很小 而且每三个一轮

然后找取博士输的情况: n为3的倍数只有全为1的时候博士输 (这也是博士先手唯一输的情况)

博士后手: n为3的倍数出现一个大于2的时候 那个人可以先选大于2的使这个数变为1 然后就是纯1的情况博士必输;

n%3==1 :

后手取走一个使得剩下所有全为1才可使博士输

如果有两堆以上大于1的石头博士每次取两个都可以胜利

然后就是n%3==2 的时候

全1先后手都赢

然后成堆后手时: 可以每次模拟为另一个n%2==2的状态 所以结果无影响 博士必胜

这是比赛的时候的代码(当时被奇偶性给弄晕了~~~) 最后九遍过,~哎,感慨实力悬殊;开始还把博士作弊一次选两堆理解错了

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <iostream>
#include<string.h>     
#include<algorithm>
#define ll long long
#include<vector>
#include<set>
using namespace std;
const int maxx=1e6+100;
int main()
{   
   int n,i,j,k,m;
    int t;
    int l,r,x;
    scanf("%d",&t);
    for(j=t;j>=1;j--)
    {
    	int sum1=0,sum2=0;
    	int a;
        scanf("%d%d",&n,&x);
        for(i=1;i<=n;i++)
        {
        	scanf("%d",&a);
        	if(a==1) sum1++;
        	else sum2++;
		}
      int flag=1;
        if(n%3==0)
		{
			if(n%2==0)
			{
				if(sum1==n&&x==1)
				flag=0;
				if(sum2<=1&&x==2) flag=0;
			}
			else
			{
				if(sum2<=1&&x==2)
                flag=0;
			}
		 } 
		 else if(n%3==1)
		 {
		 	if(n%2==0)
		 	{
		 		if(sum1==n&&x==2) flag=0;
		 		if(sum2==1&&x==2) flag=0;
			 }
			else
			{
				if(sum2<=1&&x==2) flag=0;
			}
		 }
		 else
		 {
		 	if(sum1==n) flag=1;
		 	else if(sum2==1) flag=1;
		 	else flag=1;	
		 }
		 if(flag==1)
		 printf("Yes\n");
		 else
		 printf("No\n");
		 
		
    }
    return 0;   
}

总结一下:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include <iostream>
#include<string.h>     
#include<algorithm>
#define ll long long
#include<vector>
#include<set>
using namespace std;
const int maxx=1e6+100;
int main()
{   
   int n,i,j,k,m;
    int t;
    int l,r,x;
    scanf("%d",&t);
    for(j=t;j>=1;j--)
    {
        int sum1=0,sum2=0;
        int a;
        scanf("%d%d",&n,&x);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a);
            if(a==1) sum1++;
            else sum2++;
        }
      int flag=1;
        if(n%3==0)
        {
            if(sum1==n&&x==1) flag=0;
            if(sum2==1&&x==2) flag=0;
         } 
         else if(n%3==1)
         {
             if(sum2<=1&&x==2) flag=0;
             
         }

         if(flag==1)
         printf("Yes\n");
         else
         printf("No\n");
         
        
    }
    return 0;   
}
 
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值