Educational Codeforces Round 134 (Rated for Div. 2) ABC

https://codeforces.com/contest/1721/problem/A

题目大意:您有一个大小为2×2的矩阵,由4个像素组成。每个像素可以有26种不同颜色中的一种,用小写拉丁字母表示。

您希望对图像的一些像素重新着色,以便所有4个像素都具有相同的颜色。

在一个动作中,你可以选择不超过两个相同颜色的像素,并将它们涂上其他颜色(如果你选择两个像素,两者都应该涂上相同的颜色)。

为了实现你的目标,你最少要操作多少次?
input
5
rb
br
cc
wb
aa
aa
ab
cd
yy
xx
output
1
2
0
3
1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
const LL mod=998244353;
char a[3][3];
#define x first
#define y second
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        int sum=0;
        map<char,int> mp;
        for(int i=1;i<=2;i++)
        {
            for(int j=1;j<=2;j++)
            {
                cin>>a[i][j];
                mp[a[i][j]]++;
                if(mp[a[i][j]]==1) sum++;
            }
        }
        if(sum==4) cout<<"3"<<endl;
        else if(sum==3) cout<<"2"<<endl;
        else if(sum==2) cout<<"1"<<endl;
        else cout<<"0"<<endl;
    }
    return 0;
}

https://codeforces.com/contest/1721/problem/B

题目大意:给定一个n*m的格子,有一个炸弹,d范围内的都会被炸掉

问一个人从(1,1)能否走到(n,m)这个格子里?

可以的话输出最短路,不行的话输出-1。
input
3
2 3 1 3 0
2 3 1 3 1
5 5 3 4 1
output
3
-1
8
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int n,m,x,y,d;
int a[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>x>>y>>d;
        int maxn=(n-1)+(m-1);
        bool flag=true;
        if((x+d>=n&&x-d<=1)||(y-d<=1&&y+d>=m)) flag=false;
        if((x+d>=n&&y+d>=m)||(y-d<=1&&x-d<=1)) flag=false;
        if((abs(n-x)*abs(n-x)+abs(m-y)*abs(m-y))<=d) flag=false;
        if((abs(1-x)*abs(1-x)+abs(1-y)*abs(1-y))<=d) flag=false;
        if(flag==false) cout<<"-1"<<endl;
        else cout<<maxn<<endl;
    }
    return 0;
}

https://codeforces.com/contest/1721/problem/C

题目大意:给你一个数组a1,a2,…,an,它是按非降序排列的。您决定执行以下步骤来创建数组b1,b2,…,bn:

创建一个由n个任意非负整数组成的数组d。

为每个bi设置bi=ai+di。

按非降序对数组b进行排序。

给定结果数组b。对于每个索引i,计算为了得到给定的数组b,可以选择的di的最小和最大可能值是多少。

注意,最小(最大)di-s彼此独立,即它们可以从不同的可能阵列d中获得。
input
4
3
2 3 5
7 11 13
1
1000
5000
4
1 2 3 4
1 2 3 4
4
10 20 30 40
22 33 33 55
output
5 4 2
11 10 8
4000
4000
0 0 0 0
0 0 0 0
12 2 3 15
23 13 3 15

读懂题目你就赢了。最小的从前往后,最大的从后往前
依次比较即可

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200,M=2002;
int a[N],b[N];
int minn[N],maxn[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++)
            cin>>b[i];
        for(int i=1,j=1;i<=n;i++)
        {
            while(b[j]<a[i]) j++;
            minn[i]=b[j]-a[i];
            cout<<minn[i]<<" ";
        }
        cout<<endl;
        //看最大值是否只能绑定一个数
        //如果是,就更新这一位的答案
        //继续更新b中可以使用的最大值(反向循环)
        for(int i=n,j=n;i>=1;i--)
        {
            if(i==n) maxn[i]=b[j]-a[i];
            else
            {
                if(b[i]<a[i+1]) j=i;
                maxn[i]=b[j]-a[i];
            }
        }
        for(int i=1;i<=n;i++)
            cout<<maxn[i]<<" ";
        cout<<endl;
    }
    return 0;
}
posted @ 2022-08-28 21:16  高尔赛凡尔娟  阅读(43)  评论(0编辑  收藏  举报