2021.9.20 simulation game summary + problem solution

Time:2021-10-16

summary

This test is a thinking question. I only made the rain. My thinking is not agile enough. I have to practice

Question 1: 0

Question 2: 31 (maximum score 56)

Question 3: 100

Question 4: 5

Total score: 136

Ranking: 19


Post game AK

Make up 2526

Meaning:

A sequence with length N + m + K, including n numbers 2, m numbers 5 and K numbers 6, how many subsequences are 2526 at most?

If a sequence is a subsequence of an array, if and only if the sequence can delete any element from the array, and then arrange the remaining elements in the array in order.

deduction:

Thinking problem, if you want to be the largest, you should divide n, N / 2 and a-N / 2 equally

It’s like a line-up during the game, zero

code:

#include
using namespace std;
int main()
{
    long long t,a,b,c;
    scanf("%lld",&t);
    for(int i=1;i<=t;i++)
    {
        scanf("%lld%lld%lld",&a,&b,&c);
        printf("%lld\n",(a/2)*(a-a/2)*b*c);
    }
}

In the future, we should make a good analysis and don’t think about complexity

Minimum product

Meaning:

Find two different numbers in the interval [l, R] so that their product modulus is the smallest

deduction:

It’s also a water problem

If R-L > 2019, there must be a multiple of 2019 in the middle, and the output is 0

Then directly enumerate 2019 * 2019 will not explode,

It’s a shame to make mistakes in the game

code:

#include 
using namespace std;
long long l, r, mn=1e11;
int main() {
    cin >> l >> r;
    if (r - l >= 2017 ) {
        cout << 0 << endl;
        return 0;
    }
    for (long long i = l; i <= r; i++) {
        for (long long j = i + 1; j <= r; j++) {
            mn = min(mn, i % 2019 * j % 2019);
        }
    }
    cout << mn << endl;
}

rain

Meaning:

There are n mountains in a ring, n is an odd number, and there is a dam between the two mountains.

The dam between mountain I and mountain I + 1 is called the i-th dam.

Mountain n + 1 is also the first mountain, and dam n + 1 is also the first dam.

If the rainfall of the ith mountain is fi, its rainfall will be evenly divided into the two adjacent dams.

Suppose that all the water in the dam is provided by rainfall on the mountain.

Now give the amount of water received by each dam and ask the rainfall of each mountain.

deduction:

F represents precipitation

A represents the amount of water received by the dam

Then a is known and F is unknown


Great!

Launch other unknowns

With F1, we canLaunch other unknowns

First push FN, then reverse the others

code:

First find F1

According to the above formula, odd numbers add and even numbers subtract

for(int i=1;i<=n;i++)
    {
        if(i%2==1)
        {
            f[1]+=a[i];
        }
        else
        {
            f[1]-=a[i];
        }
    }

Find FN, go backwards

f[n]=2*a[n]-f[1];
    for(int i=n-1;i>=1;i--)
    {
        f[i]=2*a[i]-f[i+1];
    }

Complete code

#include
using namespace std;
long long n,a[100005],f[100005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(i%2==1)
        {
            f[1]+=a[i];
        }
        else
        {
            f[1]-=a[i];
        }
    }
    f[n]=2*a[n]-f[1];
    for(int i=n-1;i>=1;i--)
    {
        f[i]=2*a[i]-f[i+1];
    }
    for(int i=1;i<=n;i++)
    {
        cout<

Dyeing:

Meaning:

There is a tree that contains n points. Now you want to dye all the points. You have K colors.

Two different vertices with a distance of less than or equal to 2 must be dyed in different colors.

How many dyeing schemes are there

deduction:

DFS can be implemented, but the idea is still very water, direct simulation

code:

Please read the comments carefully!!

#include
using namespace std;
struct node
{
    long long t,next;// Forward star
}a[1000005];
long long n,k,x,y,t,h[1000005],b[1000005],flag,ans=1;
Void add (int x, int y) // add edge
{
    t++;
    a[t].t=y;
    a[t].next=h[x];
    h[x]=t;
}
void dfs(int x,int y,int z)
{
    ans*=k-y-z;// Multiply by the number of alternatives
    ans%=1000000007;
    int t=0;// Indicates the number of brothers
    b[x]=1;// B indicates whether it has arrived
    for(int i=h[x];i>0;i=a[i].next)
    {
        if(b[a[i].t]==0)
        {
            If (y + 1 < = 2) // if it is not the root or the son of the root, y = 2, otherwise y + 1
            {
                dfs(a[i].t,y+1,t);
            }
            else
            {
                dfs(a[i].t,y,t);
            }
            t++;       
        }

    }
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n-1;i++)
    {
        cin>>x>>y;
        add(x,y);
        add(y,x);
    }
    dfs(1,0,0);
    If (flag) // think about it. What's the use of this?
    {
        cout<<0<