1. 程式人生 > >【AtCoder】ARC091

【AtCoder】ARC091

C - Flip,Flip, and Flip......

只有一個這一個是反面
只有一行那麼除了兩邊以外都是反面
否則輸出\((N - 2)*(M - 2)\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}

int64 N,M;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);read(M);
    int64 ans = 0;
    if(N > M) swap(N,M);
    if(N == 1 && M == 1) {puts("1");enter;}
    else if(N == 1) {
    out(M - 2);enter;
    }
    else {
    out((N - 2) * (M - 2));enter;
    }
    return 0;
}

D - Remainder Reminder

列舉模數,顯然模數需要大於K
對於一個模數小於它的\(i - K\)都合法,如果\(K = 0\)那麼是\(i - K - 1\)
對於大於等於它的,我們找到倍數在\(\lfloor\frac{N}{i}\rfloor - 1\)的部分,然後對於\(\lfloor \frac{N}{i} \rfloor \cdot i + K\)統計到N之間的個數

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,K;
int64 ans;
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);read(K);
    for(int i = 1 ; i <= N ; ++i) {
    if(i <= K) continue;
    ans += i - K;if(K == 0) --ans;
    int t = N / i - 1;
    ans += t * (i - K);
    t = N / i * i + K;
    if(t <= N) ans += N - t + 1;
    }
    out(ans);enter;
    return 0;
}

E - LISDL

最長下降子序列是由幾個最長上升子序列拼出來的

如果最長上升子序列長度為A
那麼最長下降子序列最多可以有\(N - A + 1\)
最少可以有\(\lceil \frac{N}{A}\rceil\)個,這中間的都可以通過給\(B\)個最長上升子序列分配個數實現

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <ctime>
#define fi first
#define se second
#define pii pair<int,int>
//#define ivorysi
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 300005
using namespace std;
typedef long long int64;
typedef double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9' ) {
        res = res * 10 - '0' + c;
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,A,B;
int cnt[MAXN];
void Solve() {
    read(N);read(A);read(B);
    int d = (N - 1) / A + 1,u = N - A + 1;
    if(B > u || B < d) {puts("-1");return;}
    cnt[1] = A;
    int t = N - A;
    for(int i = 2 ; i <= B ; ++i) {
        cnt[i] = t - A >= B - i ? A : t - (B - i);
        t -= cnt[i];
    }
    t = N;
    for(int i = B ; i >= 1 ; --i) {
        for(int j = t - cnt[i] + 1 ; j <= t ; ++j) {
            out(j);space;
        }
        t -= cnt[i];
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

F - Strange Nim

如果你有出色的打表技巧可以通過本題

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <ctime>
#define fi first
#define se second
#define pii pair<int,int>
//#define ivorysi
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 300005
using namespace std;
typedef long long int64;
typedef double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9' ) {
        res = res * 10 - '0' + c;
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int dfs(int a,int x) {
    
    if(a < x) return 0;
    if(a % x == 0) return a / x;
    int t = a / x,h = a % x;
    //out(a);space;out(t);space;out(h);enter;
    dfs(a - ((h - 1) / (t + 1) + 1) * (t + 1),x);
}
void Solve() {
    read(N);
    int ans = 0;
    int a,k;
    for(int i = 1 ; i <= N ; ++i) {
        read(a);read(k);
        ans ^= dfs(a,k);
    } 
    if(!ans) puts("Aoki");
    else puts("Takahashi");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}