Part 83 explanation of educational codeforces round

Note:
I haven't participated in the similar program design competition for several months, partly because of the unsatisfactory results in the latter half of 19 years, and partly because I am a little tired physically and mentally, hoping to give myself a relaxing environment. Recently, I was unable to go to school because of the epidemic at home. I originally planned to go to school for an efficient learning plan, but I was a bit lax at home. Because I need to find an internship recently, I may take some written tests and interviews, so I plan to do some competitions to activate my brain cells, so I participated in this competition.
It's been a long time since I made a question. The result of this competition is very unsatisfactory.
Partial explanation:
A.Two Regular Polygons
Title:
Give you a regular n-polygon, let you find out from these n nodes that m different nodes also form a regular m-polygon, and the center of the regular n-polygon and the regular m-polygon are the same.
Explanation:
Simple guess: n is a multiple of m.
Reason: since n=k*m, one side of a regular m polygon is equivalent to that of a regular n polygon. The centers of the two regular polygons must be together.
AC Code:

#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		if(n%m==0)
		{
			cout<<"YES\n";
		}
		else
		{
			cout<<"NO\n";
		}
		
	}
	return 0;
}

B.Bogosort
Title:
Give you an array of length n, you can change the order in the array at will, find a sequence that any I and J can satisfy j-aj ≠ \ neq  = i-ai (J < I).
Explanation:
After sorting out the problem conditions, it can be found that as long as i-j ≠ \ neq  = AI AJ (J < I) is satisfied, it is easy to find that only large to small permutations are needed to satisfy the problem.
AC Code:

#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;

int t,n,a[105];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=0;i<n;++i)
		{
			cin>>a[i];
		}
		sort(a,a+n);//sort
		for(int i=n-1;i>=0;i--)
			cout<<a[i]<<" ";
		cout<<"\n";
	}
	return 0;
}

C.Adding Powers
Title:
Give an array of n elements and an integer k. Ask if every element in an array can be added to the power of k. And each power of k can only be used once or 0 times.
Explanation:
Violence breaks down every element:
If it's a power addition of K, it must be a multiple of K. every time k is removed, the exponent is increased by one
If it is not a multiple of k, but a multiple of k plus one, then it is proved that the e-power of one of k has been found. At this time, the whole minus one, and the e-power of the mark k has been used.
If it is not the above two results, then it must not be the power addition of k.

Finally, we can judge whether a certain power of k is used more than once.

AC Code:

#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
const int maxn=1e5+5;
LL t,n,k;
LL a[maxn];
bool vis[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        bool ok=true;//Whether the mark meets the theme
        MSf(vis);
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            LL x=a[i];
            if(x==0)continue;//0 will skip directly without any power of k
            LL e=0;//Recording index
            while(x!=0)
            {
                if(x%k==0)//Remove the power of common factor k^m
                {
                    x/=k;
                    e++;
                }
                else if(x%k==1)//We find the lowest power of k in x
                {
                    x-=1;
                    if(vis[e])//If the power of e is used repeatedly, it will not satisfy the question
                    {
                        ok=false;
                        break;
                    }
                    else//Mark use
                    {
                        vis[e]=true;
                    }
                    if(x==0)break;
                }
                else//Not the power of k
                {
                    ok=false;
                    break;
                }
            }
        }
        if(ok)cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

D.Count the Arrays
Title:
A sequence satisfies the following conditions:

  1. There are n elements
  2. Each element is an integer between [1, m]
  3. There are only two identical elements in the sequence
  4. The sequence is like a mountain, high in the middle and low on both sides (the left side of the mountain increases strictly, and the right side of the mountain decreases strictly)

How many such sequences are there? The answer is modeled as 998244353.
Explanation:
Combinatorial mathematics

  1. N numbers are divided into n-1 and 1. Represents n-1 distinct numbers and 1 repeating element, respectively.
  2. The number of n-1 is selected from 1 to m, so the selection method is C(m,n-1).
  3. Since the peak (maximum) can not be repeated (otherwise it cannot meet the strict increasing decreasing), the selection of one repeated element is n-2.
  4. For this N-element sequence, the two repeated elements must be on both sides of the mountain, and the maximum value must be between the central region (2, n-1). There are two options for the remaining n-3 elements (except for the duplicate two and the peak) to be on the left or right side of the peak. As it is strictly increasing and decreasing, as long as the direction (left or right) is selected, the overall sequence will be certain. So there are 2n-3 kinds
  5. So the final result C (m,n-1) * (n-2) *2n-3.

AC Code:

#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define ll long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int maxn=1e6+10;
const LL mod=998244353;
int n,m;
LL fac[maxn],inv[maxn];
LL quickpow(LL x,LL y){//Counting
    LL res=1;
    while(y){
        if(y&1)res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
LL C(int x,int y){//Find c(n,m) by definition
    if(y<0||y>x)return 0;
    return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void init(){//Preprocessing
    fac[0]=1;
    for(int i=1;i<maxn;++i)fac[i]=fac[i-1]*i%mod;//Factorial
    inv[maxn-1]=quickpow(fac[maxn-1],mod-2);//Fermat's theorem
    for(int i=maxn-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//Inverse of factorial
}
LL two[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    init();
    two[0]=1;
    for(int i=1;i<maxn;i++)
        two[i]=two[i-1]*2%mod;
    if(n==2)//Not satisfied with the question
        cout<<0;
    else
        cout<<C(m,n-1)*(n-2)%mod*two[n-3]%mod;
    return 0;
}

Welcome to ask questions and comment!

Published 124 original articles, won praise 28, visited 10000+
Private letter follow

Tags: iOS

Posted on Tue, 10 Mar 2020 08:22:56 -0400 by madsm