Codeforces Edu Round 57 A-D

A. Find Divisible

Eligible range will be able to select \ (L, L * 2 \) .

Proof \ (l * 2 <= r \)

Assumed that there are a set of solutions, \ (X, X * D (L <= X <= R & lt, 2 <= D) \) .

Since the conditions must be satisfied: \ (L * 2 <L * = D <= X * D <= R & lt \) .

#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\n", l, l * 2);
    }
    return 0;
}

B. Substring Removal

Scanning the prefix and suffix strings:

  1. When all letters as the number of programs for all substrings \ ((1 + n) * n / 2 \)
  2. Prefix and suffix letters as letters, then either leave a prefix or suffix to stay, there is are removed.
  3. Otherwise, you can always choose two independent events can be multiplied.
#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\n", ((LL)(1 + n) * n / 2) % MOD); 
    else if(s[l] == s[r]) printf("%lld\n", ((LL)(l + 1) * (n - r + 2)) % MOD);
    else printf("%d\n", (l + (n - r + 1) + 1) % MOD);
    return 0;
}

C. Polygon for the Angle

A circumferential angle, using the central angle theorem found that ... \ (n = 180 \) when all \ (deg <179 \) can be represented, \ (n-360 = \) , all degrees can meet, so you can enumerate mess ...

#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\n", a[deg]);
    }
    return 0;
}

D. Easy Problem

\ (f [i] [j ] \) before the representation \ (i \) characters to clean up \ (Hard \) -> minimum cost $ j $ bit ago

Each encounter a \ (hard \) characters, consider before allowing j- 1 bit does not exist, before the state can be maintained, delete the character.

#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\n", f[n][3]);
    return 0;
}

Guess you like

Origin www.cnblogs.com/dmoransky/p/11286102.html