2017 ACM-ICPC 东亚总决赛 L:SOS


题目链接:2017 ACM-ICPC 东亚总决赛 L:SOS


Description
A和B在玩一个游戏:有一个长度为n的数组,他们分别在数组里填写S或O
先出现SOS的人获胜。求谁必胜或者是平局。


Sample Input
2
3
7


Sample Output
Case #1: Draw
Case #2: Panda


Solution
首先,可以看出一个必胜态一定存在一个S\_\ \_S的情况。n为奇数时且大于等于7时先手胜,n为偶数时且大于等于16时先手败。其他则是平局。


Code

import java.io.*;
import java.util.*;
public class test {
    public static void main (String[] args) {
        Scanner cin=new Scanner(System.in);
        int T=cin.nextInt();
        for (int i=1; i<=T; i=i+1) {
            int n=cin.nextInt();
            if (n>=7 && n%2==1) System.out.println("Case #"+i+": Panda");
            else if (n>=16 && n%2==0) System.out.println("Case #"+i+": Sheep");
            else System.out.println("Case #"+i+": Draw");
        }
    }
}

#include<map>
#include<set>
#include<list>
#include<queue>
#include<vector>
#include<string>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
//#define Judge
//#define Online
#define reg register
#define ll long long
#define mod 1000000007
#define inf 2147483647
#define lowbit(x) ((x)&-(x))
#define abs(x) ((x)<0?-(x):(x))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define ckmax(a,b) ((a)=max((a),(b)))
#define ckmin(a,b) ((a)=min((a),(b)))
using namespace std;
#ifdef Judge
#define puts io.put
#define getchar io.gc
#define putchar io.wchar
#ifdef Online
FILE*in=stdin;
FILE*out=stdout;
#else
FILE*in=fopen(".in","r+");
FILE*out=fopen(".out","w+");
#endif
struct FastIO{
    #define S 1000000
    int wpos,len,pos;char wbuf[S],buf[S];
    FastIO(){wpos=0,len=0,pos=0;}
    inline char gc(){
        if (pos==len) pos=0,len=fread(buf,1,S,in);
        if (pos==len) return 0; return buf[pos++];
    }
    inline void wchar(int x) {
        if (wpos==S) fwrite(wbuf,1,S,out),wpos=0;
        wbuf[wpos++]=x;
    }
    inline void put(const char*s) {for(; *s; ) wchar(*s++);}
    ~FastIO() {
        if (wpos) fwrite(wbuf,1,wpos,out),wpos=0;
    }
}io;
#endif
template<typename T> inline void read(T&x){T f=1;x=0;char c;
    for (c=getchar(); !isd(c); c=getchar()) f=(c=='-')?-1:f;
    for (; isd(c); c=getchar()) x=(x<<3)+(x<<1)+(c^48);x*=f;
}
template<typename T> inline void wt(T x,char c=0){char ch[(sizeof(T)+1)<<1];if (x<0) x=-x,putchar('-');
    int t=-1; do ch[++t]=x%10+'0',x/=10; while(x); do putchar(ch[t]); while(t--); if (c!=0) putchar(c);
}
int main(int argv,char*argc[]){
    int T;read(T);
    for (int n,Cas=1; Cas<=T; ++Cas){
        read(n);printf("Case #%d: ",Cas);
        if (n>=7&&(n&1)) puts("Panda");
        else if (n>=16&&(n^1)) puts("Sheep");
        else puts("Draw");
    }
    return 0;
}


点我回到主页

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s