题目链接:点击进入
题目
题意
一行 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;
}