• AtCoder Regular Contest 81


    链接

    C.Make a Rectangle

    给出一堆木棍的长度

    从中选4根,询问在能围成矩形的情况下,矩形的最大面积

    开个map统计一下就行

    分正方形和矩形分别统计即可

    复杂度$O(n log n)$

    #include <map>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    extern inline char gc() {
        static char RR[23456], *S = RR + 23333, *T = RR + 23333;
        if(S == T) fread(RR, 1, 23333, stdin), S = RR;
        return *S ++;
    }
    inline int read() {
        int p = 0, w = 1; char c = gc();
        while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
        while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
        return p * w;
    }
    
    #define ri register int
    #define ll long long
    
    ll ans; int n, mx;
    map <int, int> num;
    
    int main() {
        n = read();
        for(ri i = 1; i <= n; i ++) num[read()] ++;
        for(map<int, int> :: iterator it = num.begin(); it != num.end(); it ++) {
            int p1 = it -> first, p2 = it -> second;
            if(p2 >= 4) ans = max(ans, 1ll * p1 * p1);
            if(p2 >= 2) ans = max(ans, 1ll * p1 * mx), mx = p1;
        }
        printf("%lld
    ", ans);
        return 0;
    }

    D.Coloring Dominoes

    给出一个$2 * m$的网格,被$1 *2$的骨牌满覆盖

    有3种颜色,给骨牌染色,要求相领的骨牌颜色不相同,询问方案数

    分4种情况讨论即可

    自己是($1 * 2$或者$2 *2$),前置状态是($1 * 2$或者$2 * 2$)

    复杂度$O(n)$,$n = 52$...

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    #define ri register int
    #define sid 105
    #define mod 1000000007
    
    int n;
    char S[3][sid];
    
    int main() {
        cin >> n >> S[1] + 1 >> S[2] + 1;
        ri i = 1, ans;
        if(S[1][i] == S[2][i]) i = 1, ans = 3;
        else i = 2, ans = 6;
        for(i = i + 1; i <= n; i ++) {
            int p1 = S[1][i] == S[2][i];
            int p2 = S[1][i - 1] == S[2][i - 1];
            if(!p1) i ++;
            if(p1 && p2) ans = (1ll * ans * 2) % mod;
            if(!p1 && !p2) ans = (1ll * ans * 3) % mod;
            if(!p1 && p2) ans = (1ll * ans * 2) % mod;
        }
        printf("%d
    ", ans);
        return 0;
    }

    E.Don't Be a Subsequence

    询问最短的,字典序最小的,不是串$S$的子序列的字符串

    考虑序列自动机

    那么,所有不能被$S$所识别的序列一定是在识别了一段前置之后多了一个字母

    考虑虚拟一个节点$n + 1$,能转移到它说明不是串$S$的子序列

    之后就是一个拓扑图$dp$和字典序的事了

    复杂度$O(26 * n)$

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    #define ri register int
    #define sid 200050
    
    char s[sid];
    int nxt[sid][26], f[sid];
    
    int main() {
    
        scanf("%s", s + 1);
        int n = strlen(s + 1);
    
        for(ri i = 0; i < 26; i ++) nxt[n][i] = n + 1;
        for(ri i = n - 1; i >= 0; i --) {
            for(ri j = 0; j < 26; j ++) nxt[i][j] = nxt[i + 1][j];
            nxt[i][s[i + 1] - 'a'] = i + 1;
        }
    
        for(ri i = n; i >= 0; i --) {
            f[i] = 1e9;
            for(ri j = 0; j < 26; j ++)
            f[i] = min(f[i], 1 + f[nxt[i][j]]);
        }
    
        int o = 0;
        while(o != n + 1) {
            for(ri j = 0; j < 26; j ++)
            if(f[o] == f[nxt[o][j]] + 1) {
                o = nxt[o][j]; 
                printf("%c", j + 'a'); break;
            }
        } 
        return 0;
    }

    F. Flip and Rectangles

    可以任意地翻转一些行或者一些列

    询问最大子矩阵

    鬼畜的性质:一个矩阵中,如果所有的$2 *2$子矩形都有偶数个黑点,那么它就能被翻转出来

    证明网上一大堆

    然后令$v[i][j]$表示以$(i, j)$为左上角存不存在$2 *2$偶数黑点矩阵

    问题转化为求最大子矩阵

    注意特判一行,一列

    注意计算答案时,求出来的最大子矩阵的长和宽是原题中最大子矩阵长和宽 - 1的结果

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    #define ri register int
    #define sid 2005
    
    char s[sid];
    int n, m, ans;
    bool v[sid][sid], c[sid][sid];
    short h[sid][sid], l[sid][sid], r[sid][sid];
    short L[sid][sid], R[sid][sid];
    
    int main() {
        
        scanf("%d%d", &n, &m);
        for(ri i = 1; i <= n; i ++) {
            scanf("%s", s + 1);
            for(ri j = 1; j <= m; j ++)
            c[i][j] = (s[j] == '#') ? 1 : 0;
        }
    
        for(ri i = 1; i < n; i ++)
        for(ri j = 1; j < m; j ++)
        v[i][j] = c[i][j] ^ c[i + 1][j] ^ c[i][j + 1] ^ c[i + 1][j + 1] ^ 1;
    
        for(ri i = 1; i <= n; i ++) {
            int lst = 0;
            for(ri j = 1; j <= m; j ++)
            if(v[i][j]) l[i][j] = lst;
            else L[i][j] = 0, lst = j;
            
            lst = m + 1;
            for(ri j = m; j >= 1; j --)
            if(v[i][j]) r[i][j] = lst;
            else R[i][j] = m + 1, lst = j;
        }
    
        for(ri i = 0; i <= m + 1; i ++) R[0][i] = m + 1;
    
        ans = max(n, m);
        for(ri i = 1; i <= n; i ++)
        for(ri j = 1; j <= m; j ++)
        if(v[i][j]) {
            h[i][j] = h[i - 1][j] + 1;
            L[i][j] = max((short)(l[i][j] + 1), L[i - 1][j]);
            R[i][j] = min((short)(r[i][j] - 1), R[i - 1][j]);
            ans = max(ans, (R[i][j] - L[i][j] + 2) * (h[i][j] + 1));
        }
    
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    ubuntu 15.10 64bit 下 steam无法启动
    ubuntu下使用OBS开斗鱼直播
    sql server 2008 management studio安装教程
    navicat for mysql 破解版
    nginx 重写去掉index.php
    phpstorm 注册码破解
    tp where使用数组条件,如何设置or,and
    PHPstorm 配置主题
    IE下无法保存Cookie和Session问题
    GitLab的安装及使用
  • 原文地址:https://www.cnblogs.com/reverymoon/p/9713854.html
Copyright © 2020-2023  润新知