2015年6月7日 星期日

Looksery Cup 2015, problem: (C) The Game Of Parity

先爆艘出來,然後印出來看規律XD 真有夠喇

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int,int> pii;

map<pii, int> sv;

int detS(int,int,int);
int detD(int,int,int);

int detD(int a, int b, int step){
    if(step == 0) return (b&1)^1;
    if(sv.count(pii(a, b))) return sv[pii(a, b)];
    if(a and detS(a-1, b, step-1) == 1){sv[pii(a, b)] = 1;return 1;}
    if(b and detS(a, b-1, step-1) == 1){sv[pii(a, b)] = 1;return 1;}
    sv[pii(a, b)] = 0; return 0;
}

int detS(int a, int b, int step){
//    printf("detS %d %d %d\n", a, b, step);
    if(step == 0) return (b&1)^1;
    if(sv.count(pii(a, b))) return sv[pii(a, b)];
    if(a and detD(a-1, b, step-1) == 0){
        sv[pii(a, b)] = 0;
        return 0;
    }
    if(b and detD(a, b-1, step-1) == 0){
        sv[pii(a, b)] = 0;
        return 0;
    }
    sv[pii(a, b)] = 1;
    return 1;
}

int ans(int a, int b, int step){
    if(step == 0) return (b&1)^1;
    if(step&1){
        if(a+b < step) return (a^b^1)&1;
        if(a >= (step+1)/2 and b >= (step+1)/2) return 0;
        if(a < b) return (a^b)&1;
        return 1;
    }
    if(a <= step/2) return (a^b^1)&1;
    if(a+b <= step) return (a^b^1)&1;
    return 1;
}

int main(){
    int n, t; scanf("%d %d", &n, &t);
    int a[2] = {0};
    for(int lx = 0;lx < n;lx++){
        int inp; scanf("%d", &inp);
        a[inp&1]++;
    }
/*
    for(int step = 0;step < 10;step++){
        printf("step = %d\n", step);
        for(int lx = 0;lx < 10;lx++){
            for(int ly = 0;ly < 10;ly++){
                sv.clear();
                printf("%d", detS(lx, ly, step));
                if(detS(lx, ly, step) != ans(lx, ly, step))
                    while(1);
            }
            printf("\n");
        }
        puts("======");
    }
    sv.clear();*/
    puts(ans(a[0], a[1], n-t) ? "Daenerys" : "Stannis");

    return 0;
}

沒有留言:

張貼留言