【AtCoder】ARC062

ARC062

C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report

每次看看比率至少变成多少倍能大于当前的数

然后就把两个人的票都改成那个数

#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);
}
int N;
int64 T,A;
int64 gcd(int64 a,int64 b) {
    return b == 0 ? a : gcd(b,a % b);
}
void Solve() {
    read(N);
    int64 t = 1,a = 1;
    for(int i = 1 ; i <= N ; ++i) {
        read(T);read(A);
        int64 k = (t - 1) / T + 1,h = (a - 1) / A + 1;
        k = max(k,h);
        t = k * T,a = k * A;
    }
    out(a + t);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

D - AtCoDeerくんと変なじゃんけん / AtCoDeer and Rock-Paper

布可以让你少输一个或多赢一个,所以能出布就出布,只要以石头布石头布不变应万变就好了

#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);
}
int N;
char s[MAXN];
void Solve() {
    scanf("%s",s + 1);
    N = strlen(s + 1);
    int ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
        if(i & 1) {
            if(s[i] == 'p') ans--;
        }
        else {
            if(s[i] == 'g') ans++;
        }
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

E - AtCoDeerくんと立方体づくり / Building Cubes with AtCoDeer

怎么是个暴力。。。

只要枚举对面的两个面,所有的面都可以被固定下来,然后对面的那个面旋转一下

把一个面的四种情况扔进一个map里,每次查询固定后的四个面,查询到一个面把这个面转四次带来的贡献在map里给减掉,就完成了去重

要注意如果这个面不存在要提前退出,不然map里会加入无用的情况,会T

#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);
}
int N;
int c[MAXN][4];
int64 h[MAXN];
map<int64,int> zz;
void insert(int64 p,int d) {
    for(int i = 0 ; i < 4 ; ++i) {
        zz[p] += d;
        p = p / 1000 + (p % 1000) * 1000000000LL;
    }
}
int64 calc(int64 a,int64 b,int64 c,int64 d) {
    int64 res = d + c * 1000 + b * 1000000 + a * 1000000000;
    return res;
}
int64 getcol(int64 p,int t) {
    for(int i = 0 ; i < 3 - t ; ++i) p /= 1000;
    return p % 1000;
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        for(int j = 0 ; j < 4 ; ++j) {
            read(c[i][j]);
        }
        h[i] = calc(c[i][0],c[i][1],c[i][2],c[i][3]);
        insert(h[i],1);
    }
    int64 ans = 0;
    for(int i = 1 ; i <= N ; ++i) {
        insert(h[i],-1);
        for(int j = i + 1 ; j <= N ; ++j) {
            insert(h[j],-1);
            for(int k = 0 ; k < 4 ; ++k) {
                int64 res = 1;

                int64 rec[4] = {0};
                rec[0] = calc(getcol(h[i],0),getcol(h[j],1),getcol(h[j],0),getcol(h[i],1));
                rec[1] = calc(getcol(h[i],1),getcol(h[j],0),getcol(h[j],3),getcol(h[i],2));
                rec[2] = calc(getcol(h[i],2),getcol(h[j],3),getcol(h[j],2),getcol(h[i],3));
                rec[3] = calc(getcol(h[i],3),getcol(h[j],2),getcol(h[j],1),getcol(h[i],0));
                for(int x = 0 ; x < 4 ; ++x) {
                    res = res * zz[rec[x]];
                    if(!res) {
                        for(int y = 0 ; y < x ; ++y) {
                            insert(rec[y],1);
                        }
                        goto fail;
                    }
                    insert(rec[x],-1);
                }
                for(int x = 0 ; x < 4 ; ++x) {
                    insert(rec[x],1);
                }
                fail:;
                ans += res;
                h[j] = h[j] / 1000 + (h[j] % 1000) * 1000000000;
            }
            insert(h[j],1);
        }
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

F - AtCoDeerくんとグラフ色塗り / Painting Graphs with AtCoDeer

考虑一个点双(因为是简单环),如果没有环(两点一线),那么乘上K

如果有一个环,那么用polya定理,每个置换圈有gcd(i,n)个循环节

如果有两个及以上的环,任何一种置换都合法,那么只和每个颜色用了多少个有关,用插板法算组合数就是\(\binom{n + k - 1}{k - 1}\)

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
//#define ivorysi
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mo 974711
#define RG register
#define MAXN 200005
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) {putchar('-');x = -x;}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M,K;
struct node {
    int to,next;
}E[1005];
int head[55],sumE,fac[205],invfac[205],dfn[55],low[55],idx,sta[105],top,col[55],cnt,ans;
vector<int> ver;
int mul(int a,int b) {return 1LL * a * b % MOD;}
int inc(int a,int b) {a = a + b;if(a >= MOD) a -= MOD;return a;}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
    if(c & 1) res = mul(res,t);
    t = mul(t,t);
    c >>= 1;
    }
    return res;
}
int gcd(int a,int b) {
    return b == 0 ? a : gcd(b,a % b);
}
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
int C(int n,int m) {
    if(n < m) return 0;
    return mul(mul(fac[n],invfac[m]),invfac[n - m]);
}
void Tarjan(int u,int fa) {
    dfn[u] = low[u] = ++idx;
    sta[++top] = u;
    for(int i = head[u] ; i ; i = E[i].next) {
    int v = E[i].to;
    if(v != fa) {
        if(dfn[v]) low[u] = min(low[u],dfn[v]);
        else {
        Tarjan(v,u);
        if(low[v] >= dfn[u]) {
            ver.clear();
            ++cnt;
            col[u] = cnt;
            ver.pb(u);
            while(1) {
            int x = sta[top--];
            col[x] = cnt;
            ver.pb(x);
            if(x == v) break;
            }
            int tot = 0;
            for(auto k : ver) {
            for(int j = head[k] ; j ; j = E[j].next) {
                if(col[E[j].to] == cnt) ++tot;
            }
            }
            tot /= 2;
            if(tot == 1) ans = mul(ans,K);
            else if(tot == ver.size()) {
            int t = 0;
            for(int j = 1 ; j <= tot ; ++j) {
                t = inc(t,fpow(K,gcd(tot,j)));
            }
            t = mul(t,fpow(tot,MOD - 2));
            ans = mul(ans,t);
            }
            else ans = mul(ans,C(tot + K - 1,K - 1));
        }
        else low[u] = min(low[v],low[u]);
        }
    }
    }
}
void Solve() {
    read(N);read(M);read(K);
    int u,v;
    for(int i = 1 ;i <= M ; ++i) {
    read(u);read(v);add(u,v);add(v,u);
    }
    fac[0] = 1;
    for(int i = 1 ; i <= 200; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[200] = fpow(fac[200],MOD - 2);
    for(int i = 199 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    ans = 1;
    for(int i = 1 ; i <= N ; ++i) {
    if(!dfn[i]) Tarjan(i,0);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}
上一篇:抓老鼠~亏了还是赚了


下一篇:【AtCoder】ARC059