zoukankan      html  css  js  c++  java
  • 【AtCoder】ARC081

    C - Make a Rectangle

    每次取两个相同的且最大的边,取两次即可

    #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 MAXN 100005
    #define eps 1e-12
    //#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,a[MAXN];
    map<int,int> zz;
    void Solve() {
        read(N);
        for(int i = 1 ; i <= N ; ++i) {read(a[i]);zz[a[i]]++;}
        int r = 0,c = 0;
        while(1) {
            if(zz.empty()) break;
            auto t = *(--zz.end());zz.erase(--zz.end());
            if(t.se >= 2) {
                if(!r) r = t.fi;
                else if(!c) c = t.fi;
            }
            if(t.se > 2) zz[t.fi] = t.se - 2;
            if(r && c) break;
        }
        out(1LL * r * c);enter;
    }
    int main() {
    #ifdef ivorysi
    	freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    D - Coloring Dominoes

    就是如果是
    竖条对两个长条,那么方案数乘上2
    竖条对竖条,乘上2
    两个长条+竖条,方案数乘上1
    两个长条+两个长条 有3种
    1 2
    2 1

    1 3
    2 1

    1 2
    2 3

    初始如果一个竖条有3种,两个横条有6种

    #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 MAXN 100005
    #define eps 1e-12
    //#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 N,f[65];
    char s[2][65];
    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);
        scanf("%s%s",s[0] + 1,s[1] + 1);
        int ans = 0;
        for(int i = 1 ; i <= N ; ++i) {
            if(s[0][i] == s[0][i + 1]) continue;
            if(s[0][i - 1] == s[0][i]) {
                if(i <= 2) ans = 6;
                else {
                    if(f[i - 2] == 0) ans = mul(ans,3);
                    else if(f[i - 2] == 1) ans = mul(ans,2);
                }
                f[i] = 0;
            }
            else {
                if(i <= 1) ans = 3;
                else {
                    if(f[i - 1] == 1) ans = mul(ans,2);
                }
                f[i] = 1;
            }
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
    	freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    E - Don't Be a Subsequence

    撞题了吧,最短不公共子串的那个模板大礼包

    直接建序列自动机,求最短路,每次从前往后遍历走一条最短路边

    #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 MAXN 200005
    #define eps 1e-12
    //#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);
    }
    char a[MAXN];
    int nxt[MAXN][26],N,dis[MAXN];
    string ans = "";
    void Solve() {
        scanf("%s",a + 1);
        N = strlen(a + 1);
        for(int i = 0 ; i < 26 ; ++i) nxt[N][i] = N + 1;
        for(int i = N - 1 ; i >= 0 ; --i) {
            for(int j = 0 ; j < 26 ; ++j) nxt[i][j] = nxt[i + 1][j];
            nxt[i][a[i + 1] - 'a'] = i + 1;
        }
        dis[N + 1] = 0;
        for(int i = N ; i >= 0 ; --i) {
            dis[i] = N + 1;
            for(int j = 0 ; j < 26 ; ++j) dis[i] = min(dis[nxt[i][j]] + 1,dis[i]);
        }
        int pos = 0;
        while(pos != N + 1) {
            for(int i = 0 ; i < 26 ; ++i) {
                if(dis[nxt[pos][i]] + 1 == dis[pos]) {
                    ans += (i + 'a');
                    pos = nxt[pos][i];
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    int main() {
    #ifdef ivorysi
    	freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    

    F - Flip and Rectangles

    我们认为一个长方形任意一个22的方格如果包含偶数个黑点
    那么一定会变成全黑
    我们把每个2
    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('
    ')
    #define MAXN 2005
    #define eps 1e-12
    //#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 H,W,ans;
    char s[MAXN][MAXN];
    int tr[MAXN],tl[MAXN],h[MAXN],l[MAXN],r[MAXN];
    bool check(int x,int y) {
        return ((s[x - 1][y - 1] == '#') + (s[x - 1][y] == '#') + (s[x][y - 1] == '#') + (s[x][y] == '#')) & 1;
    }
    void Solve() {
        read(H);read(W);
        ans = max(H,W);
        for(int i = 0 ; i < H ; ++i) {
            scanf("%s",s[i]);
        }
        for(int i = 1 ; i <= W - 1; ++i) l[i] = 0,r[i] = W;
        tr[W] = W;
        for(int i = 1 ; i < H ; ++i) {
            for(int j = 1 ; j < W ; ++j) {
                if(check(i,j)) tl[j] = j;
                else tl[j] = tl[j - 1];
            }
            for(int j = W - 1 ; j >= 1 ; --j) {
                if(check(i,j)) tr[j] = j;
                else tr[j] = tr[j + 1];
            }
            for(int j = 1 ; j < W ; ++j) {
                if(check(i,j)) {
                    h[j] = 0,l[j] = 0,r[j] = W;
                }
                else {
                    l[j] = max(tl[j],l[j]);
                    r[j] = min(tr[j],r[j]);
                    h[j]++;
                    ans = max(ans,(r[j] - l[j] - 1 + 1) * (h[j] + 1));
                }
            }
        }
        out(ans);enter;
    }
    int main() {
    #ifdef ivorysi
    	freopen("f1.in","r",stdin);
    #endif
        Solve();
    }
    
  • 相关阅读:
    移动端开发touchstart,touchmove,touchend事件详解和项目
    我对JVM的理解
    快速排序
    归并排序(Merge sort)
    希尔排序
    插入排序
    选择排序
    冒泡排序(Bubble Sort)
    java设计模式之单例模式
    Java中反射机制的理解
  • 原文地址:https://www.cnblogs.com/ivorysi/p/10424888.html
Copyright © 2011-2022 走看看