Codeforces Edu Round 60 A-E

A. Best Subsegment

显然,选择数列中的最大值当做区间(长度为\(1\))。只要尝试最大值这个区间是否能扩展(左右两边值是否跟它一样就行了)

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int N = 100010;
int n, a[N], val = -1, res = -1;
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        val = max(val, a[i]);
    }
    int len = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] == val) len ++;
        else len = 0;
        res = max(res, len);
    }
    printf("%d\n", res);
    return 0;
}

B. Emotes

贪心。让总和最大,考虑可以尽量选最大的,每次选\(k\)次,然后选一个第二大的,接着选\(k\)次最大的...就这样轮替。这个过程可以用取余来快速完成,每一轮的次数是\(k + 1\)。

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 200010;
int n, m, k, a[N], max1 = -1, max2 = -1;
LL res = 0;
int main(){
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if(a[i] > max1){
            max2 = max1;
            max1 = a[i];
        }else if(a[i] > max2){
            max2 = a[i];
        }
    }
    int num = m / (k + 1), ot = m % (k + 1);
    printf("%lld\n", (LL)num * k * max1 + (LL)num * max2 + (LL)ot * max1);

    return 0;
}

C. Magic Ship

二分答案。容易看出,时刻符合单调性。若\(d\)天能到,那么\(d + 1\)也能到。因为可以保持跟风相反的方向就可以保持不动,晚一个时刻在到。如果设置\(check\)函数,我们先把这些天风走的走完,再看现在的曼哈顿距离是否够天数走完的即可。对于二分答案的上界,可以设置为\(1e14\),最坏情况所有\(n\)次只有一次是顺方向,剩下都是逆方向,那么每\(n\)次只能动\(2\)步,结合最大需求曼哈顿是\(1e9 * 2 = 2e9\),所以最高时间就是\(n * 2e9 / 2 = 100000 * 2e9 / 2 = 1e14\)。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const int N = 100010;
typedef long long LL;
int x, y, x2, y2, n, sum[N][2];
char s[N];
//检查x时间是否可行。
bool check(LL d){
    LL nx = x, ny = y;
    nx += (d / n) * sum[n][0] + sum[d % n][0];
    ny += (d / n) * sum[n][1] + sum[d % n][1];
    return abs(x2 - nx) + abs(y2 - ny) <= d;
}
int main(){
    scanf("%d%d%d%d%d%s", &x, &y, &x2, &y2, &n, s + 1);
    for(int i = 1; i <= n; i++){
        sum[i][1] += sum[i - 1][1] + (s[i] == 'U');
        sum[i][1] -= (s[i] == 'D');
        sum[i][0] -= (s[i] == 'L');
        sum[i][0] += sum[i - 1][0] + (s[i] == 'R');
    }
    if(!check(1e14)) puts("-1");
    else{
        LL l = 1, r = 1e14;
        while(l < r){
            LL mid = (l + r) >> 1;
            if(check(mid))r = mid;
            else l = mid + 1;
        }
        printf("%lld\n", r);
    }

    return 0;
}

D. Magic Gems

考虑\(dp\),每次有两个决策,一个是放\(m\)个普通宝石,或者放一个\(1\)个魔法宝石。

设\(f[i]\)为填i个区间的方案数,状态转移方程\(f[i] = f[i - 1] + f[i - m]\)

初始化\(f[1] = f[2] = ... = f[m - 2] = f[m - 1] = 1\)。

然后我就不会优化了...只能看题解,发现要用矩阵快速幂 or 杜教优化,但是本蒟蒻两个都不会,所以这个坑以后再填...

E. Decypher the String

我自闭了。既然可以二进制确定一个范围,那么我们尝试\(26\)进制系列,因为字母各不相同可以确定转换位置。由于\(26 ^ 2 < 10000 < 26 ^ 3\),范围之内可以解决。

询问三个分别如下:

  1. \(aaaa(26 * 26)bbbb(26 * 26)...zzzz(26 * 26)\)
  2. \(aaaa(26)bbbb(26)...zzzz(26)aaaa...\)
  3. \(abcdefghijklmn...xyzabcd...xyz...\)

这样每一步可以将答案缩小至原来的\(\frac{1}{26}\),在范围可以解决问题。

为了方便找到交集,我们用\(bitset\)即可。

PS:这毒瘤输入输出...这个它提示我输入格式不正确。

#include <cstdio>
#include <iostream>
#include <bitset>
#include <cstring>
using namespace std;
const int N = 10000;
char str[N], s[3][N], ans[N];
bitset<N> a[3][26];
int n;
int main(){
    scanf("%s", str);
    n = strlen(str);
    for(int i = 0; i < n; i++)
        for(int j = 0, t = i; j < 3; j++)
            s[j][i] = t % 26 + 'a', t /= 26;

    for(int i = 0; i < 3; i++){
        printf("? %s\n", s[i]), fflush(stdout), scanf("%d", s[i]);
    }

    for(int i = 0; i < 3; i++)
        for(int j = 0; j < n; j++)
            a[i][s[i][j] - 'a'].set(i);

    for(int i = 0; i < n; i++){
        bitset<N> u;
        for(int j = 0, t = i; j < 3; j++)
            u &= a[j][t % 26], t /= 26;
        for(int j = 0; j < n; j++)
            if(u[j]) { ans[i] = str[j]; break; }
    }
    printf("! %s\n", ans);
    return 0;
}

然后我改成单个的就对了,wtf????

#include <cstdio>
#include <iostream>
#include <bitset>
#include <cstring>
using namespace std;
const int N = 10005;
char str[N], s1[N], s2[N], s3[N], ans[N];
bitset<N> a[3][26], now;
int n;
int main(){
    scanf("%s", str);
    n = strlen(str);
     for (int i = 0; i< n; ++i) {
        int t = i;
        s1[i] = 'a' + t % 26; t /= 26;
        s2[i] = 'a' + t % 26; t /= 26;
        s3[i] = 'a' + t % 26; t /= 26;
    }
    printf("? "); puts(s1); fflush(stdout); scanf("%s", s1);
    printf("? "); puts(s2); fflush(stdout); scanf("%s", s2);
    printf("? "); puts(s3); fflush(stdout); scanf("%s", s3);

    for (int i = 0; i < n; ++i) a[0][s1[i] - 'a'].set(i);
    for (int i = 0; i < n; ++i) a[1][s2[i] - 'a'].set(i);
    for (int i = 0; i < n; ++i) a[2][s3[i] - 'a'].set(i);

    for (int i = 0; i < n; ++i) {
        int t = i;
        now = a[0][t % 26]; t /= 26;
        now &= a[1][t % 26]; t /= 26;
        now &= a[2][t % 26]; t /= 26;
        for (int j = 0; j < n; ++j)
            if (now[j]) { ans[i] = str[j]; break; }
    }
    printf("! %s\n", ans);
    return 0;
}

原因应该是字符数组二维读入上和输出没有好的规定......

原文地址:https://www.cnblogs.com/dmoransky/p/11296807.html

时间: 2024-11-03 00:45:29

Codeforces Edu Round 60 A-E的相关文章

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

CodeForces Beta Round #1

Codeforces Beta Round #1 A. Theatre Square [题意]一个n*m的矩形广场,用a*a的方形石板铺设,问最少需要多少块石板能铺满广场. [思路]水题,从n方向来看能能够铺设ceil(n/a)块,从m方向来看能能够铺设ceil(m/a)块,总共有ceil(n/a)*ceil(m/a)块. 1 /* 2 ** CodeForces 1A Theatre Square 3 ** Created by Rayn @@ 2014/05/18 4 */ 5 #inclu

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

题目传送门 1 /* 2 BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 3 只要撑过这个时间就能win,否则lose 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <queue> 8 #include <vector> 9 #include <cstring> 10 using namespace std; 11 1

Codeforces Beta Round#2

Codeforces Beta Round#2 http://codeforces.com/contest/2 A 模拟题 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 map<string,ll>mp; 6 struct sair{ 7 string str; 8 int id; 9 ll num; 10 }a[1005]; 11 12 bool cmp(sair a,sa

Codeforces Beta Round #3

Codeforces Beta Round #3 http://codeforces.com/contest/3 A 找规律题.但我懒得找,直接暴搜 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*

Codeforces Beta Round #5

Codeforces Beta Round #5 http://codeforces.com/contest/5 A 模拟题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLI

Codeforces Beta Round #6 (Div. 2 Only)

Codeforces Beta Round #6 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7 typedef long long ll; 8 /*#ifndef

Codeforces Beta Round #7

Codeforces Beta Round #7 http://codeforces.com/contest/7 A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7 typedef long lon