• 【AtCoder】ARC065


    ARC065

    C - 白昼夢 / Daydream

    直接递推就好

    #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('
    ')
    #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);
    }
    string s;
    int dp[MAXN];
    void Solve() {
        cin >> s;
        dp[0] = 1;
        for(int i = 1 ; i <= s.length() ; ++i) {
    	if(i >= 5) {
    	    dp[i] |= (dp[i - 5] && s.substr(i - 5,5) == "dream");
    	    dp[i] |= (dp[i - 5] && s.substr(i - 5,5) == "erase");
    	}
    	if(i >= 6) {
    	    dp[i] |= (dp[i - 6] && s.substr(i - 6,6) == "eraser");
    	}
    	if(i >= 7) {
    	    dp[i] |= (dp[i - 7] && s.substr(i - 7,7) == "dreamer");
    	}
        }
        if(dp[s.length()]) puts("YES");
        else puts("NO");
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    

    D - 連結 / Connectivity

    把图两次染色,然后标号,会得到一个点对,这个点对相同的点才在两个图里都连通

    #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('
    ')
    #define eps 1e-10
    #define MAXN 200005
    //#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<pii,int> zz;
    int N,K,L;
    int fa[MAXN],col[MAXN][2],tot;
    int getfa(int x) {
        return fa[x] == x ? x : fa[x] = getfa(fa[x]);
    }
    void Solve() {
        read(N);read(K);read(L);
        for(int i = 1 ; i <= N ; ++i) fa[i] = i;
        int a,b;
        for(int i = 1 ; i <= K ; ++i) {
    	read(a);read(b);
    	fa[getfa(a)] = getfa(b);
        }
        tot = 0;
        for(int i = 1 ; i <= N ; ++i) {
    	if(getfa(i) == i) col[i][0] = ++tot;
        }
        for(int i = 1 ; i <= N ; ++i) col[i][0] = col[getfa(i)][0];
        for(int i = 1 ; i <= N ; ++i) fa[i] = i;
        for(int i = 1 ; i <= L ; ++i) {
    	read(a);read(b);
    	fa[getfa(a)] = getfa(b);
        }
        tot = 0;
        for(int i = 1 ; i <= N ; ++i) {
    	if(getfa(i) == i) col[i][1] = ++tot;
        }
        for(int i = 1 ; i <= N ; ++i) col[i][1] = col[getfa(i)][1];
        for(int i = 1 ; i <= N ; ++i) {
    	zz[mp(col[i][0],col[i][1])]++;
        }
        for(int i = 1 ; i <= N ; ++i) {
    	out(zz[mp(col[i][0],col[i][1])]);space;
        }
        enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    

    E - へんなコンパス / Manhattan Compass

    曼哈顿转切比雪夫

    然后把点对排序,每个点用横坐标相连就是

    (x_{a} - x_{b} = D)

    并且$ -D<= y_{a} - y_{b} <= D$

    这是一段区间,我们可以把区间里的点两两相连,再和a点相连,是等价的

    然后记录每个点连出去的边有多少,和初始的两个点连通的所有点之间的边数加起来就是答案

    #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('
    ')
    #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);
    }
    struct node {
        int to,next;
    }E[MAXN * 10];
    int head[MAXN],sumE;
    int N,a,b;
    int x[MAXN],y[MAXN],D,id[MAXN],cnt[MAXN];
    pii p[MAXN],tmp[MAXN];
    int st[MAXN],ed[MAXN];
    int fa[MAXN];
    int getfa(int x) {
        return fa[x] == x ? x : fa[x] = getfa(fa[x]);
    }
    void Merge(int x,int y) {
        fa[getfa(x)] = getfa(y);
    }
    void AddE(int on) {
        for(int i = 1 ; i <= N ; ++i) {
    	id[i] = i;
        }
        sort(id + 1,id + N + 1,[](int a,int b){return p[a] < p[b];});
        memset(st,0,sizeof(st));memset(ed,0,sizeof(ed));
        
        for(int i = 1 ; i <= N ; ++i) {
    	tmp[i] = p[id[i]];
        }
        for(int i = 1 ; i <= N ; ++i) {
    	int l = lower_bound(tmp + 1,tmp + N + 1,mp(tmp[i].fi + D,tmp[i].se - D + on)) - tmp;
    	int r = upper_bound(tmp + 1,tmp + N + 1,mp(tmp[i].fi + D,tmp[i].se + D - on)) - tmp - 1;
    	if(l <= r) {
    	    st[l]++;ed[r]++;
    	    Merge(id[i],id[l]);
    	    cnt[id[i]] += r - l + 1;
    	}
        }
        int pre = 0;
        for(int i = 1 ; i < N ; ++i) {
    	pre += st[i];pre -= ed[i];
    	if(pre) Merge(id[i],id[i + 1]);
        }
    }
    void Solve() {
        read(N);read(a);read(b);
        for(int i = 1 ; i <= N ; ++i) {
    	read(x[i]);read(y[i]);
    	fa[i] = i;
        }
        
        D = abs(x[a] - x[b]) + abs(y[a] - y[b]);
        for(int i = 1 ; i <= N ; ++i) p[i] = mp(x[i] + y[i],x[i] - y[i]);
        AddE(0);
        for(int i = 1 ; i <= N ; ++i) swap(p[i].fi,p[i].se);
        AddE(1);
        int64 ans = 0;
        for(int i = 1 ; i <= N ; ++i) {
    	if(getfa(i) == getfa(a)) ans += cnt[i];
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    

    F - シャッフル / Shuffling

    就是对于一个区间,记录能用a个0和b个1

    然后对于某个位置填0还是填1

    由于能用的数是总和是确定的,我们只要记录当前有a个0没用就可以了

    #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('
    ')
    #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);
    }
    const int MOD = 1000000007;
    int ri[MAXN],f[2][MAXN];
    int N,M;
    char s[MAXN];
    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 update(int &x,int y) {
        x = inc(x,y);
    }
    void Solve() {
        read(N);read(M);
        scanf("%s",s + 1);
        int l,r;
        for(int i = 1 ; i <= M ; ++i) {
    	read(l);read(r);
    	ri[l] = max(ri[l],r);
        }
        int p = 0,all = 0;
        int cur = 0;
        f[cur][0] = 1;
        
        for(int i = 1 ; i <= N ; ++i) {
    	if(p < i - 1) {p = i - 1;}
    	if(ri[i] > p) {
    	    all += ri[i] - p;
    	    int a = 0,b = 0;
    	    for(int j = p + 1 ; j <= ri[i] ; ++j) {
    		if(s[j] == '0') ++a;
    		else ++b;
    	    }
    	    p = ri[i];
    	    memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
    	    for(int j = a ; j <= N ; ++j) f[cur ^ 1][j] = f[cur][j - a];
    	    cur ^= 1;
    	}
    	if(!all) continue;
    	memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
    	for(int j = 0 ; j <= all ; ++j) {
    	    if(j < all) update(f[cur ^ 1][j],f[cur][j]);
    	    if(j >= 1) update(f[cur ^ 1][j - 1],f[cur][j]);
    	}
    	--all;
    	cur ^= 1;
        }
        out(f[cur][0]);enter;
    }
    int main() {
    #ifdef ivorysi
        freopen("f1.in","r",stdin);
    #endif
        Solve();
        return 0;
    }
    
  • 相关阅读:
    HDFS API
    Wrong FS: hdfs://xxx/xxx expected: file:///
    Sqoop拒绝连接错误
    MySQL设置远程连接
    Eclipse远程连接Hadoop
    Hadoop创建新用户
    Nutch的安装和配置
    NameNode重新格式化以后DataNode不能启动
    Pig拒绝连接错误
    Pig jline.Terminal错误
  • 原文地址:https://www.cnblogs.com/ivorysi/p/10856672.html
Copyright © 2020-2023  润新知