Gym - 101775L-SOS ( 博弈 )

题目链接:点击进入
题目

在这里插入图片描述
在这里插入图片描述

题意

一行 1 * n 的网格,熊猫跟绵羊分别在格子里下棋(棋子为 S 或者 O ),熊猫先手,先凑成 SOS 的人获胜。如果最后都没凑成就平局。

思路

经过一通乱写,发现 S _ _ S 这种情况下,谁先手谁输。( 暂且称这种情况为决胜局 )
但是想要凑成这种情况必须 n >= 7
只有当 n >= 7 时,熊猫取中间为 S ,接下来不论绵羊取哪个,熊猫都可以凑出决胜局面 ,但是这种局面,不是每一种都是熊猫胜
只有当 n 是 奇数 的时候熊猫才必胜,
当 n 为 偶数 的时候,熊猫不会赢,但可能平局。
这时候局面就转换成求绵羊必胜的情况了。
当 n >= 16 时,无论熊猫怎么放,绵羊总能选出一个长度 >= 7 区间,这就变相相当于在这个区间绵羊先手,先手且区间长度 >= 7 ,那么绵羊就是必胜。
剩下的全是平局的情况。

代码:
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
//#define double long double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const int maxn=1e6+10;
const int mod=1e9+7;
const double eps=1e-9;
int t,n,a[maxn]; 
int main()
{	
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	cin>>t;
	for(int i=1;i<=t;i++)
	{
		cin>>n;
		cout<<"Case #"<<i<<": ";
		if(n<7) cout<<"Draw"<<endl;
		else if(n&1) cout<<"Panda"<<endl;
		else if(n<16)
			cout<<"Draw"<<endl;
		else
			cout<<"Sheep"<<endl;
	}
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值