1. 程式人生 > >洛谷5月月賽

洛谷5月月賽

Task1

n堆石子,每次可以從第i堆中取走一個當且僅當Ni > Ni-1(第0堆視作0個)。拿不了就輸了。問先手贏還是後手贏。

奇偶性問題。不管如何分佈,必定全部被拿完。

#include <cstdio>
inline char gc() {
    static char now[1<<16], *S, *T;
    if(S == T) {T = (S = now) + fread(now, 1, 1<<16, stdin); if(S == T) return EOF;}
    return *S++;
}
inline int read() {
    int x = 0, f = 1; char c = gc();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = gc();}
    while(c >= '0' && c <= '9') {x = x * 10 + c - 48; c = gc();}
    return x * f;
}
int n, a[110];
int main() {
    n = read(); long long ans = 0;
    for(int i = 1; i <= n; ++i) a[i] = read();
    for(int i = 1; i <= n; ++i) ans+= a[i];
    if(ans % 2 == 1) puts("Alice");
    else puts("Bob");
    return 0;
}

Task2

可以計算得知,無論如何也不可能蓋住四條邊界。於是列舉四條邊界的整數點即可。

#include <cstdio>
#define mo 1e-7
double x[110], y[110];
int n, l;
inline double getdis(double x1, double y1, double x2, double y2) {return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);}
int main() {
    scanf("%d%d", &n, &l);
    for(int i = 1; i <= n; ++i) scanf("%lf%lf", &x[i], &y[i]);
    for(int i = 0; i <= l; ++i) {
        int X, Y; bool flag;
        X = 0; Y = i; flag = 1;
        for(int j = 1; j <= n; ++j) {
            double dis = getdis(X, Y, x[j], y[j]);
            if(dis < (((double)l/n) + ((double)1e-6)) * (((double)l/n) + ((double)1e-6))) {flag = 0; break;}
        }
        if(flag == 1) {printf("%d %d", X, Y); return 0;}
        
        
        X = l; Y = i;
        flag = 1;
        for(int j = 1; j <= n; ++j) {
            double dis = getdis(X, Y, x[j], y[j]);
            if(dis < (((double)l/n) + ((double)1e-6)) * (((double)l/n) + ((double)1e-6))) {flag = 0; break;}
        }
        if(flag == 1) {printf("%d %d", X, Y); return 0;}
        
        
        
        X = i; Y = 0;
        flag = 1;
        for(int j = 1; j <= n; ++j) {
            double dis = getdis(X, Y, x[j], y[j]);
            if(dis < (((double)l/n) + ((double)1e-6)) * (((double)l/n) + ((double)1e-6))) {flag = 0; break;}
        }
        if(flag == 1) {printf("%d %d", X, Y); return 0;}
        
        
        
        X = i; Y = l;
        flag = 1;
        for(int j = 1; j <= n; ++j) {
            double dis = getdis(X, Y, x[j], y[j]);
            if(dis < (((double)l/n) + ((double)1e-6)) * (((double)l/n) + ((double)1e-6))) {flag = 0; break;}
        }
        if(flag == 1) {printf("%d %d", X, Y); return 0;}
        
        
        
        
    }
    puts("GG");
    return 0;
}