Codeforces Round #628 (Div. 2)

A. EhAb AnD gCd

Description

给定一正整数 \(x\),求正整数\(a,b\),使得 \(gcd(a,b) + lcm(a,b) = x\)

Solution

\(a = 1\) 即可。

#include<bits/stdc++.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;scanf("%d",&n);
        printf("1 %d\n",n-1);
    }
    return 0;
}

B. CopyCopyCopyCopyCopy

Description

给定一个数组,求由这个数组复制 Codeforces Round #628 (Div. 2)_#include 次产生的数组的最大上升(严格)子序列长度。

Solution

只需在第一次复制中选择最小的,在第二次复制中选择次小的,以此类推即可。

故答案即为数组中不同元素个数,使用 std::unique 获得。

#include<bits/stdc++.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n, a[100100];scanf("%d",&n);
        for(int i=1;i<=n;i++) scanf("%d",a+i);
        std::sort(a+1,a+n+1);
        int ans = std::unique(a+1,a+n+1)-(a+1);
        printf("%d\n",ans);
    }
    return 0;
}

C. Ehab and Path-etic MEXs

Codeforces Round #628 (Div. 2)_子序列_02

#include<bits/stdc++.h>
const int maxn= 1e5+100;
using namespace std;
int a[maxn],b[maxn],num[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        num[a[i]]++;num[b[i]]++;
    }
    int op = 0;
    for(int i=1;i<=n;i++) if(num[i]>=3) {op = i; break;}
    if(!op) for(int i=0;i<n-1;i++) printf("%d\n",i);
    else
    {
        for(int i=1,cnt1=0,cnt2=3;i<n;i++)
        {
            if((a[i]==op || b[i]==op) && cnt1<=2) printf("%d\n",cnt1++);
            else printf("%d\n",cnt2++);
        }
    }
    return 0;
}

D. Ehab the Xorcist

Codeforces Round #628 (Div. 2)_c++_03

#include<bits/stdc++.h>
typedef long long ll;
int main()
{
    ll x,s;
    scanf("%lld%lld",&x,&s);
    if(s==0 && x==0) printf("0\n");
    else if(s==x) printf("1\n%lld",s);
    else if(s<x) printf("-1\n");
    else if((s-x)%2) printf("-1\n");
    else{
        ll sub = s-x;
        ll a = sub/2, b = s-a;
        if((a^b)==x) printf("2\n%lld %lld",a,b);
        else printf("3\n%lld %lld %lld",x,sub/2,sub/2);
    }
    return 0;
}

The desire of his soul is the prophecy of his fate
你灵魂的欲望,是你命运的先知。