Codeforces Round #839 (Div. 3) ABCD

昨晚忙着找py数据分析入门了,又🕊了,下午vp了补上,D好奇妙啊(也有可能是我变笨了)
https://codeforces.com/contest/1772
A. A+B?

题目大意:

给定A+B的字符串,AB都在10以内,求结果
input 
4
4+2
0+0
3+7
8+9
output 
6
0
10
17
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        string s;
        cin>>s;
        cout<<(s[0]-'0')+(s[2]-'0')<<endl;
    }
    return 0;
}

B. Matrix Rotation

题目大意:

给定2*2的矩阵,问我们是否可以通过旋转 满足:每一行都处以递增状态,每一列都处于递增状态
inputCopy
6
1 3
5 7
8 10
3 4
8 10
4 3
6 1
9 2
7 5
4 2
1 2
4 3
outputCopy
YES
YES
NO
YES
YES
NO
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
LL a[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        for(int i=1;i<=2;i++)
        {
            for(int j=1;j<=2;j++)
            {
                cin>>a[i][j];
            }
        }
        bool flag=false;
        if(a[1][1]<a[1][2]&&a[2][1]<a[2][2]&&a[1][1]<a[2][1]&&a[1][2]<a[2][2]) flag=true;
        if(a[2][1]<a[2][2]&&a[2][1]<a[1][1]&&a[1][2]>a[1][1]&&a[1][2]>a[2][2]) flag=true;
        if(a[2][2]<a[1][2]&&a[2][2]<a[2][1]&&a[1][1]>a[2][1]&&a[1][1]>a[1][2]) flag=true;
        if(a[1][2]<a[1][1]&&a[1][2]<a[2][2]&&a[2][1]>a[1][1]&&a[2][1]>a[2][2]) flag=true;
        if(flag==true) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C. Different Differences

题目大意:

让我们构造k个数字,从1到n的范围内

需要满足严格单调递增并且最大化相邻两两相减的差的不同值的数量
inputCopy
7
5 9
4 12
3 3
3 4
4 4
4 6
8 11
outputCopy
1 3 4 7 8
2 4 7 12
1 2 3
1 3 4
1 2 3 4
2 4 5 6
1 2 3 5 6 7 8 11
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL k,n;
        cin>>k>>n;
        for(int i=1;i<=k;i++)
            a[i]=i;
        LL maxn=1;
        for(int i=3;i<=k;i++)
        {
            if(a[i-1]+(maxn+1)+(k-i)<=n)
            {
                a[i]=a[i-1]+(maxn+1);
            }
            else a[i]=a[i-1]+1;
            maxn=a[i]-a[i-1];
        }
        for(int i=1;i<=k;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}

D. Absolute Sorting

题目大意:

给定一个数组a,判断是否存在一个数值x,让这个数组减去x后呈递增状态,注意减去后要取绝对值a[i] = abs(a[i] - x);

存在,输出任意一个x,否则输出-1。
inputCopy
8
5
5 3 3 3 5
4
5 3 4 5
8
1 2 3 4 5 6 7 8
6
10 5 4 3 2 1
3
3 3 1
3
42 43 42
2
100000000 99999999
6
29613295 52036613 75100585 78027446 81409090 73215
outputCopy
4
-1
0
42
2
-1
100000000
40741153
  1. 如果已经是递增序列的话,直接输出0;
  2. 如果已经是递减序列的话,直接输出第一个数字,那么序列中所有数字在经过减去第一个数字后也呈现递增状态
  3. 对于两个不相等的数字a,b,标记值应该为这两个数的中间的那个数字,分别更新最大值r和最小值l,如果最小满足的值都会大于最大满足的值的话,就是不符合的;反之就可以随便输出这个答案区间内的任意数字
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=5000200,M=2002;
LL a[N],b[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            b[i]=a[i];
        }
        //先把单调递增和单调递减的特判掉
        bool flag=true;
        sort(b+1,b+1+n);
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=b[i])
            {
                flag=false;
                break;
            }
        }
        if(flag==true) cout<<"0"<<endl;
        else
        {
            flag=true;
            reverse(b+1,b+1+n);
            for(int i=1;i<=n;i++)
            {
                if(a[i]!=b[i])
                {
                    flag=false;
                    break;
                }
            }
            if(flag==true) cout<<a[1]<<endl;
            else
            {
                LL l=-1,r=MAXN;
                for(int i=1;i<=n-1;i++)//两两对比
                {
                    if(a[i]>a[i+1])
                    {
                        LL flag=a[i]-((a[i]-a[i+1])/2);//AG
                        l=max(l,flag);
                    }
                    else if(a[i]<a[i+1])
                    {
                        LL flag=a[i]+((a[i+1]-a[i])/2);
                        r=min(r,flag);
                    }
                }
                if(l>r) cout<<"-1"<<endl;
                else cout<<l<<endl;
            }
        }
    }
    return 0;
}
posted @ 2022-12-19 22:13  高尔赛凡尔娟  阅读(51)  评论(0编辑  收藏  举报