Codeforces Round # 563 (Div. 2) solution to a problem

Construction. . .

A. Ehab Fails to Be Thanos

The meaning of problems

To give you a length \ (2N \) sequence, the sequence is rearranged so that the front half and the rear half and not equal. No solution output \ (--1 \) .

answer

Obviously if all the numbers are equal certainly no solution, otherwise it can be sorted.

Code ugly not posted ......

B. Ehab Is an Odd Person

The meaning of problems

To give you a length \ (n-\) sequence \ (A_1, \ DOTS, A_N \) , if the \ (a_i + a_j \) is odd you can swap the two numbers. Seeking the smallest lexicographic sequence you can get. \ (n-\ Le. 5 ^ 10 \) .

answer

Obviously if all the numbers are odd or even answer the original series. Otherwise, for the same two parity number we can by a parity exchange different points, the answer is sorted sequence.

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gi()
{
    char c; int x=0,f=1;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
    return x*f;
}
const int N=1e5+5;
int n,a[N],sa[N],rk[N],sum1,sum2;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("b.in","r",stdin);
#endif
    n=gi();
    for(int i=1;i<=n;++i) a[i]=gi(),sum1+=(a[i]%2==0),sum2+=(a[i]%2);
    if(sum1&&sum2) sort(a+1,a+1+n);
    for(int i=1;i<=n;++i) printf("%d ",a[i]);
}

C. Ehab and a Special Coloring Problem

The meaning of problems

Configured a length \ (n-\) sequence, such that the subscript two mutually prime numbers and positions of maximum value as small as possible range. \ (n-\ Le. 5 ^ 10 \) .

answer

Sieve method can be run directly.

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gi()
{
    char c; int x=0,f=1;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
    return x*f;
}
const int N=2e5+5;
int a[N];
bool p[N];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("c.in","r",stdin);
#endif
    int n; scanf("%d",&n);
    int cnt=0;
    for(int i=2;i*i<=n;++i)
    {
        if(!p[i])
        {
            a[i]=++cnt;
            for(int j=i*i;j<=n;j+=i) p[j]=true,a[j]=cnt;
        }
    }
    for(int i=2;i<=n;++i) printf("%d ",a[i]?a[i]:++cnt);
}

D. Ehab and the Expected XOR Problem

The meaning of problems

You \ (n, x \) each constructed as a long number \ (\ le 2 ^ n \ ) sequence of such sub-segment is not present and the exclusive OR \ (0 \) or \ (X \ ) .

\ (1 \ n \ 18, 1 \ the x <2 ^ {18} \)

answer

Consider prosequence prefix and XOR \ (S_I \) , the conversion conditions that there is no \ (s_i \ oplus s_j = x \) and \ (S_I S_j = \) , i.e., a maximum of only appear \ (S_I \) or \ (S_I \ oplus the X-\) .

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int gi()
{
    char c; int x=0,f=1;
    for(;c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+c-'0';
    return x*f;
}
const int N=3e5+5;
bool vis[N];
int v[N],cnt;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("d.in","r",stdin);
#endif
    int n,x,lst=0;
    scanf("%d%d",&n,&x);
    vis[x]=true;
    for(int i=1;i<(1<<n);++i)
        if(!vis[i]) vis[i^x]=true,v[++cnt]=lst^i,lst=i;
    printf("%d\n",cnt);
    for(int i=1;i<=cnt;++i) printf("%d ",v[i]);
}

Guess you like

Origin www.cnblogs.com/farway17/p/10971355.html