Mr. Panda and Mr. Sheep are playing a game on a 1 × N game board. Initially, all the cells are empty. Mr. Panda and Mr. Sheep take alternate moves and Mr.Panda moves first.

On each move, a player must fill an 'S' or 'O' into an empty cell. After the move, if there are 3 consecutive cells from left to right form the word "SOS", the player wins the game and the game finished.

If the board gets filled up without SOS appearing consecutively, no one wins the game, the game end with draw.

Now, if both Mr. Panda and Mr. Sheep play optimally, find out the result of the game.

「Gym 101775L」SOS

代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 1e5+10;
int a[maxd];
int main()
{
//    freopen("a.in","r",stdin);
//    freopen("k.out","w",stdout);
int t;scanf("%d",&t);
//printf("%lld\n",t);
for(int tt = 1;tt <= t;tt++)
{
int n;scanf("%d",&n);
int flag;
if(n < 7) flag = 1;
else if(n %2 == 0 && n < 16)  flag =1;
else if(n %2 == 0 )flag =0;
else flag = 2;
if(flag == 1) printf("Case #%d: Draw\n",tt);
else if(flag == 2) printf("Case #%d: Panda\n",tt);
else printf("Case #%d: Sheep\n",tt);
}
return 0;
}