• Codeforces Edu Round 57 A-D


    A. Find Divisible

    符合条件的区间一定可以选择(l, l * 2)

    证明(l * 2 <= r)

    假设存在一组解,(x, x * d (l <= x <= r, 2 <=d ))

    因为必定满足条件则:(l * 2 <= l * d <= x * d <= r)

    #include <cstdio>
    #include <iostream>
    using namespace std;
    int main(){
        int T; scanf("%d", &T);
        while(T--){
            int l, r; scanf("%d%d", &l, &r);
            printf("%d %d
    ", l, l * 2);
        }
        return 0;
    }
    

    B. Substring Removal

    扫描字符串的前缀和后缀:

    1. 若所有字母一样,方案数为所有子串((1 + n) * n / 2)
    2. 前缀字母与后缀字母一样,则要么留下前缀,要么留后缀,还有就是都去掉。
    3. 否则,则两者可以都选,独立事件可以相乘。
    #include <iostream>
    #include <cstdio>
    using namespace std;
    typedef long long LL;
    const int N = 200010, MOD = 998244353;
    int n;
    char s[N];
    int main(){
        scanf("%d%s", &n, s + 1);
        int l = 1, r = n;
        while(s[l] == s[l + 1]) l++;
        while(s[r] == s[r - 1]) r--;
        if(l == n && r == 1) printf("%lld
    ", ((LL)(1 + n) * n / 2) % MOD); 
        else if(s[l] == s[r]) printf("%lld
    ", ((LL)(l + 1) * (n - r + 2)) % MOD);
        else printf("%d
    ", (l + (n - r + 1) + 1) % MOD);
        return 0;
    }
    

    C. Polygon for the Angle

    一个圆周角、圆心角定理的运用…发现当(n = 180) 的时候,所有(deg < 179) 都可以表示出来,(n = 360)时,所有度数均可满足,于是就可以枚举惹...

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    const int N = 190;
    int a[N * 2];
    int main(){
        for(int i = 3; i <= 360; i++){
            for(int j = 1; j <= i - 2; j++){
                if(180 * j % i == 0 && (!a[180 * j / i]))
                    a[180 * j / i] = i; 
            }
        }
        int T; scanf("%d", &T);
        while(T--){
            int deg; scanf("%d", &deg);
            printf("%d
    ", a[deg]);
        }
        return 0;
    }
    

    D. Easy Problem

    (f[i][j])表示前(i)个字符 清理到(hard) -> 前$ j$ 位的最小花费

    每次遇到一个(hard)中字符,考虑可以让前 j- 1位不存在,也可以保持之前的状态,删除这个字符。

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    using namespace std;
    const int N = 100010;
    typedef long long LL;
    char s[N];
    int n, a[N];
    LL f[N][4];
    //f[i][j] 前i个字符 清理到"hard" -> j 位 
    int main(){
        memset(f, 0x3f, sizeof f);
        for(int i = 0; i < 4; i++) f[0][i] = 0;
        scanf("%d%s", &n, s + 1);
        for(int i = 1; i <= n; i++) scanf("%d", a + i);
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < 4; j++) f[i][j] = f[i - 1][j];
            if(s[i] == 'h') f[i][0] = f[i - 1][0] + a[i];
            if(s[i] == 'a') f[i][1] = min(f[i - 1][0], f[i - 1][1] + a[i]); 
            if(s[i] == 'r') f[i][2] = min(f[i - 1][1], f[i - 1][2] + a[i]); 
            if(s[i] == 'd') f[i][3] = min(f[i - 1][2], f[i - 1][3] + a[i]); 
        }
        printf("%lld
    ", f[n][3]);
        return 0;
    }
    
  • 相关阅读:
    高清摄像头MIPI接口与ARM处理器的连接
    How to make apq8084
    DBI接口和DPI接口的区别
    MIPI DSI协议介绍
    LCD显示的一些基本概念以及DSI的一些clock解释
    AXI总线
    SPI,UART,I2C都有什么区别,及其各自的特点
    图像滤镜处理算法:灰度、黑白、底片、浮雕
    用到的一些算法收集
    实用Linux命令,不求最全但求实用-------iptables命令实战
  • 原文地址:https://www.cnblogs.com/dmoransky/p/11286102.html
Copyright © 2020-2023  润新知