Educational Codeforces Round 59 (Rated for Div. 2)(ABCD)

A. Digits Sequence Dividing

题意:给你一个数字串,只包含1-9,让你至少分成两段,使得每一段的数字大于前一段的数字;

解:对n特判,如果n为2,那么比较一下两个数字大小,如果n>2,那么就可以直接分成两部分,第一部分1个数字,剩下都为第二部分;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+10;
const int mod=998244353;
ll ans[maxn];
int main(){
    int T;
    cin>>T;
    while(T--){
        int n;
        string s;
        cin>>n>>s;
        if(n==2){
            if(s[0]<s[1]){
                cout<<"YES"<<endl;
                cout<<"2"<<endl;
                cout<<s[0]<<‘ ‘<<s[1]<<endl;
            }
            else cout<<"NO"<<endl;
        }
        else {
            cout<<"YES"<<endl;
            cout<<"2"<<endl;
            cout<<s[0]<<‘ ‘;
            for(int i=1;i<n;i++)cout<<s[i];
            cout<<endl;
        }

    }

    return 0;
}

B. Digital root

题意:给你一个S(x),让你求第k个x;S(5)=5,S(38)=S(3+8=11)=S(1+1=2)=2;

比如从5 1   有:1 10 19 28 37 46 发现规律:m+(n-1)*9

解:写几个推下公式就蒙过去了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+10;

int main(){
    int T;
    cin>>T;
    while(T--){
        ll n,m;
        cin>>n>>m;
        cout<<9LL*(n-1)+1LL*m<<endl;
    }

    return 0;
}

C. Brutality

题意:一个字符串,26个字母,每个位置的字母都有一个价值,连续字母出现不能超过k次,如果超过的需要删除掉,问你能获得的最大价值是多少;

解:暴力咯,把连续相同的字母放在优先队列里面,然后不连续之后从队列里面拿出k个,其他的都不要。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll a[maxn];
priority_queue<int>que;
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    string s;
    cin>>s;
    que.push(a[0]);
    ll ans=0LL;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]){
            que.push(a[i]);
        }
        else{
            int cnt=0;
            while(!que.empty()){
                if(cnt>=m)break;
                ans+=que.top();que.pop();
                cnt++;
            }
            while(!que.empty())que.pop();
            que.push(a[i]);
        }
    }
    int cnt=0;
    while(!que.empty()){
        if(cnt>=m)break;
        ans+=que.top();que.pop();
        cnt++;
    }
    while(!que.empty())que.pop();
    cout<<ans<<endl;

    return 0;
}

D. Compression

题意:(自己做的时候还看不懂题意)看了下题解,原来是求把矩阵A能分成最大的矩阵B,满足矩阵B的长度能够被A的长度整除,

且A种B的规格的块要么满足都为1,要么满足都为0才行;

解:把二维前缀和先预处理一下,然后再去枚举n到1矩阵的规格,利用二维前缀和可以快速判断是否满足条件;

#include <bits/stdc++.h>
using namespace std;
const int maxn=5300;
int a[maxn][maxn],pre[maxn][maxn];
string s;
int n;
bool check(int x){
    for(int i=0;i<n;i+=x){
        for(int j=0;j<n;j+=x){
            int now=pre[i+x][j+x]+pre[i][j]-pre[i+x][j]-pre[i][j+x];
            if(now!=0&&x*x!=now){
                return false;
            }
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int j=0;j<n/4;j++){
            int x=0;
            if(s[j]>=‘A‘&&s[j]<=‘Z‘)
                x=10+s[j]-‘A‘;
            else x=s[j]-‘0‘;
            a[i][4*j+3]=x>>0&1;
            a[i][4*j+2]=x>>1&1;
            a[i][4*j+1]=x>>2&1;
            a[i][4*j+0]=x>>3&1;
        }
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<a[i][j]<<‘ ‘;
        }
        cout<<endl;
    }*/
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            pre[i+1][j+1]=pre[i][j+1]+pre[i+1][j]-pre[i][j]+a[i][j];
        }
    }
    for(int i=n;i>=1;i--){
        if(n%i==0){
            if(check(i)){
                cout<<i<<endl;
                return 0;
            }
        }
    }

    return 0;
}

原文地址:https://www.cnblogs.com/lin1874/p/11406124.html

时间: 2024-10-31 13:40:19

Educational Codeforces Round 59 (Rated for Div. 2)(ABCD)的相关文章

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构

Educational Codeforces Round 59 (Rated for Div. 2) E 区间dp + 状态定义

https://codeforces.com/contest/1107/problem/E 题意 给出01字符串s(n<=100),相邻且相同的字符可以同时消去,一次性消去i个字符的分数是\(a[i]\),问消去s最多能得到多少分数 题解 实质是安排消去次序使得分数最大,第一步采取的行动是递归边界 因为只有01串,所以s被分成了一段一段,考虑段处理 预处理出一次性消去i个字符的最大分数\(f[i]\) 定义\(dp[l][r][cnt]\)为消去第l到第r段加上cnt个字符和第l段相同得到的最大

Educational Codeforces Round 59 (Rated for Div. 2) (前四题)

A. Digits Sequence Dividing(英文速读) 练习英语速读的题,我还上来昏迷一次....只要长度大于2那么一定可以等于2那么前面大于后面就行其他no 大于2的时候分成前面1个剩下后面一定是对的因为按照数字大小 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n;

Educational Codeforces Round 59 (Rated for Div. 2)

A.Digits Sequence Dividing 题意:给你一个1-9的数字字符串,把它划分成若干段(>=2)段,使其大小递增. 错误:当长度为2的时候没考虑 #include<cstdio> #include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<map> using

Educational Codeforces Round 49 (Rated for Div. 2) ABCD

A. Palindromic Twist You are given a string ss consisting of nn lowercase Latin letters. nn is even. For each position ii (1≤i≤n1≤i≤n) in string ss you are required to change the letter on this position either to the previous letter in alphabetic ord

Educational Codeforces Round 56 (Rated for Div. 2) ABCD

题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次,能使扔出的总和等于xi. 题解: 由于是special judge,模拟一下搞搞就行了= = 代码如下: #include <bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; int n; while(t--

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is