【AtCoder】ARC068

ARC 068

C - X: Yet Another Die Game

顯然最多的就是一次6一次5c++

最後剩下的可能須要多用一次6或者6和5都用上數組

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 3005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
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 +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 s,n;
void Solve() {
    read(s);
    n = (s / 11) * 2;
    s %= 11;
    if(s > 0 && s <= 6) n += 1;
    if(s > 6) n += 2;
    out(n);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

D - Card Eater

就是奇數的卡片最後確定能全消掉,只剩一個優化

偶數的卡片最後會剩兩個,看看兩兩配對,最後會不會剩一個,剩一個證實確定須要少一種數,不然就是原來序列中不一樣的數的個數spa

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
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 +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);
}
map<int,int> zz;
int N;
int a[MAXN];
void Solve() {
    read(N);
    int cnt = 0,p = 0;
    for(int i = 1 ; i <= N ; ++i) {
    read(a[i]);
    zz[a[i]]++;
    }
    for(auto t : zz) {
    ++cnt;
    if(t.se % 2 == 0) p ^= 1;
    }
    out(cnt - p);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

E - Snuke Line

對於一個d來講,咱們把大於等於d的區間所有刪掉3d

而後給\(l - 1\)標記成+1,\(r\)標記成-1,這些區間裏能被d訪問到的個數是code

d - 1的前綴和2d - 1的前綴和,3d - 1的前綴和....隊列

直接樹狀數組維護就行了get

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
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 +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,M;
int tr[MAXN],ans[MAXN];
pii p[MAXN];
int lowbit(int x) {return x & (-x);}
void insert(int x,int v) {
    ++x;
    while(x <= M + 1) {
    tr[x] += v;
    x += lowbit(x);
    }
}
int query(int x) {
    int v = 0;++x;
    while(x > 0) {
    v += tr[x];
    x -= lowbit(x);
    }
    return v;
}
void Solve() {
    read(N);read(M);
    for(int i = 1 ; i <= N ; ++i) {
    read(p[i].fi);read(p[i].se);
    --p[i].fi;
    insert(p[i].fi,1);insert(p[i].se,-1);
    }
    sort(p + 1,p + N + 1,[](pii a,pii b){return a.se - a.fi < b.se - b.fi;});
    int id = N;
    int cnt = 0;
    for(int i = M ; i >= 1 ; --i) {
    while(id >= 1 && p[id].se - p[id].fi >= i) {
        insert(p[id].fi,-1);insert(p[id].se,1);
        ++cnt;--id;
    }
    ans[i] = cnt;
    int t = i;
    while(t <= M) {
        ans[i] += query(t - 1);
        t += i;
    }
    }
    for(int i = 1 ; i <= M ; ++i) {out(ans[i]);enter;}
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

F - Solitaire

大意是有一個雙端隊列,從1到N往裏面扔數,再從隊首或者隊尾取數,要求第K個必須是1,求方案數it

這個就看什麼樣的是合法的,咱們發現若是當前沒選到1,已經選了i個數,最小的是j,咱們要麼就選一個比j還小的,要麼選一個當前沒選過的最大的class

這個能夠用前綴和優化去dp

當選到第k個以後,就是剩下的序列要麼選最大的,要麼選最小的,看看乘上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 space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
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 +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 MOD = 1000000007;
int K,N;
int dp[2005][2005],sum[2005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void Solve() {
    
    read(N);read(K);
    dp[0][N + 1] = 1;
    for(int i = 1 ; i <= K ; ++i) {
    sum[N + 2] = 0;
    for(int j = N + 1 ; j >= 1 ; --j)  sum[j] = inc(sum[j + 1],dp[i - 1][j]);
    for(int j = 1 ; j <= N ; ++j) {
        if(i == K && j != 1) continue;
        if(i < K && j == 1) continue;
        dp[i][j] = sum[j + 1];
        if((N - j + 1) > (i - 1)) dp[i][j] = inc(dp[i][j],dp[i - 1][j]);
    }
    }
    int t = 1;
    for(int i = 1 ; i < N - K ; ++i) {
    t = mul(t,2);
    }
    out(mul(dp[K][1],t));enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}
相關文章
相關標籤/搜索