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 namespace std;
typedef long long ll;
const int p=998244353;
int n,q;
char s[1010];
int main()
{
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&n);
        scanf("%s",s);
        if(s[0]<s[1]||n>2)
        {
            printf("YES\n");
            printf("2\n");
            printf("%c ",s[0]);
            for(int j=1;j<n;j++) printf("%c",s[j]);
            printf("\n");
        }
        else{
            printf("NO\n");
        }
    }
}

B.Digital root

题意:求第k大的数根为x的数

补充知识:数根(digital root)公式的推导

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
const int p=998244353;
int n,q;
ll k,x;
char s[1010];
int main()
{
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%I64d%I64d",&k,&x);
        printf("%I64d\n",(k-1)*9+x);
    }
}

C.Brutality

题意:给你两个序列,第一个为价值,第二个为种类,求价值最大(一个限制条件是在种类相同的段里不能选超过k个)

思路:对个每个小段快排,取前k大。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int p=998244353;
int n,k,a[201010],q[201000];
char s[201000];
ll ans;
vector<int> mp[30];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    scanf("%s",s+1);
    int w=1,flag=s[1];q[1]=a[1];
    for(int i=2;i<=n;i++)
    {
        if(s[i]!=flag)
        {
            sort(q+1,q+1+w,cmp);
            for(int j=1;j<=min(w,k);j++)
            ans+=q[j];
            w=1;flag=s[i];q[1]=a[i];
        }
        else{
            q[++w]=a[i];
        }
    }
    sort(q+1,q+1+w,cmp);
    for(int j=1;j<=min(w,k);j++)
            ans+=q[j];
//    for(int i=1;i<=n;i++)
//    {
//        mp[s[i]-97].push_back(a[i]);
//    }
//    for(int i=0;i<=29;i++)
//        sort(mp[i].begin(),mp[i].end());
//    for(int i=0;i<=29;i++)
//    {
//        for(int j=mp[i].size()-1;j>=0;j--)
//           {
//               ans+=mp[i][j];
//               printf("%I64d %d\n",ans,mp[i].size());
//               if(mp[i].size()-j+1>k) break;
//           }
//    }
    printf("%I64d\n",ans);
}

D.Compression

题意:对于一个01矩形找到最大的矩形,使其满足

思路1:这道题的题意就是分解成若干最大的矩形是,使其内的值都为0或者1。用sum[i][j]表示二维前缀和,时间复杂度O(n*n*π*π/6)

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int p=998244353;
int n,mp[5210][5210],sum[5210][5210],flag,w[10100];
char s[201010];
bool chec(int x,int y,int k)
{
    //printf("%d %d %d\n",x,y,k);
    int zhi=sum[x*k][y*k]-sum[(x-1)*k][y*k]-sum[x*k][(y-1)*k]+sum[(x-1)*k][(y-1)*k];
    //printf("zhi=%d\n",zhi);
    if(zhi==0||zhi==k*k) return 0;
    return 1;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        for(int j=0;j<strlen(s);j++)
        {
            int x;
            if(s[j]<=‘9‘) x=s[j]-‘0‘;
            else x=s[j]-‘A‘+10;
            int l=0;
            while(x>0)
            {
                mp[i][4*(j+1)-l]=x%2;
                x/=2;l++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+mp[i][j];
        }
    }
    int l=0;
    for(int i=1;i<=trunc((double)sqrt(n));i++)
        if(n%i==0)
        {
        w[++l]=i;w[++l]=n/i;
        }
    sort(w+1,w+1+l);
    for(int i=l;i>=1;i--)
    {
        flag=0;
        int kuai=n/w[i];
    //    printf("%d\n",kuai);
        for(int k=1;k<=kuai;k++)
        {
            for(int j=1;j<=kuai;j++)
            if(chec(k,j,w[i]))
            {
                flag=1;
    //            printf("   %d\n",w[i]);
                break;
            }
        if(flag) break;
        }
        if(!flag)
        {
            flag=w[i];
            break;
        }
    }
    printf("%d\n",flag);
}

思路2:巧妙官方题解,

原文地址:https://www.cnblogs.com/The-Pines-of-Star/p/10336301.html

时间: 2024-11-06 03:32:09

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

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)(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=9982

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

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

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w