2020/08/20 Summer Team Contest

2020/08/20

Time is tight recently, the last team match has not been concluded yet, so I will make up today.
August 20 is the day before yesterday. My condition is not very good and my thoughts are very messy. A water question is asked. Old Kong said that he seems to have done question A before. He directly gave question A to AC. Old Yan is in state Yes, I took three questions for A, and I looked at question C with Lao Kong. I thought about my ideas. He wrote the code and gave question C to question A. I thought about question J for a while, which is a bipartite graph matching. The question, but no A (Hungarian algorithm forgot), in the end our team has a total of 5 questions, the middle level.

topic

H.Non-random numbers

Insert picture description hereOne water question.
Meaning of the question: Given an n, ask you how many n-digits meet the condition.
The condition is that a number position cannot be 0, and then the number in the i-th position cannot be i.
Idea: First, there are only 8 situations in the first place, then there are 9 situations in the 2-9 places, and there are 10 situations thereafter. Here is another little trick: 1<n<100, the data size of long long int is not enough, we can convert (*10) into (output a 0).

AC code:

#include <stdio.h>
#include<stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    
    
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    scanf("%d",&n);
    if(n<10)
    {
    
    
        long long int sum=8;
        for(int i=1; i<n; i++)
            sum*=9;
        printf("%lld\n",sum);
    }
    else
    {
    
    
        long long int sum=8;
        for(int i=1; i<9; i++)
            sum*=9;
        printf("%lld",sum);
        for(int i=10; i<=n; i++)
            printf("0");
    }
    return 0;
}

C.Desktop

Insert picture description hereThe meaning of the question: zoom into a 2×2 icon on a rectangular desktop of a given size. The icons can overlap, but half of the size (that is, 1×2 size) must be exposed to be effective. Ask how many icons can be effective at most, output The location of these icons.
Idea: Here is a way to solve the problem (maybe the answer is not unique) Insert picture description here. The grid marked with 0 in the figure is a wasted grid. The layer method is to paint every two rows in a way that they overlap each other (if there are odd numbers) Just paint the last line two by two) and then rotate the chart by 90 degrees and paint the last two lines in the same way as before (because painting like this will only waste two grids at the end, while the previous drawing method will waste at least two grids). The total number of icons that can be put in this painting method is n×m/2-1.

AC code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> 
int main() {
    
    
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, i, j;
    scanf("%d %d",&n,&m);
    if (n < 2 || m < 2) {
    
    
        printf("0\n");
    }
    else {
    
    
        printf("%d\n",n*m/2-1);
        if (n % 2 == 1) //判断行数是否为奇数
        {
    
    
            for (i = m - 1; i >= 1; i -= 2)
            {
    
    
                printf("%d %d\n", 1, i);
            }
        }
        for (i = n - 1; i >= 1; i -= 2) 
        {
    
    
            for (j = m - 1; j >= 2; j--) 
            {
    
    
                printf("%d %d\n", i, j);
            }
        }
        for (i = n - 1; i >= 1; i--) 
        {
    
    
            if (i < 2 && n % 2 == 1)
                break;
            printf("%d %d\n", i, 1);
        }
    }
    return 0;
}

J - Architect of Your Own Fortune

Insert picture description hereInsert picture description hereMatching bipartite graphs directly sets the template (Hungarian algorithm).
First use an array to store the sum of the first three and the last three of each string, and then see who can match with whom.
AC code

#include <bits/stdc++.h>
using namespace std;
int n, m;
char s1[110][10], s2[110][10];
int q1[110], h1[110], q2[110], h2[110];
int rel[110][110], memory[110], vic[110];
int AT[110][110] = {
    
     0 }, TA[110][110] = {
    
     0 };
bool f(int x)
{
    
    
	int i;
	for (i = 0; i < m; i++)
	{
    
    
		if (rel[x][i] && !memory[i])
		{
    
    
			memory[i] = 1;
			if (vic[i] == -1 || f(vic[i]))
			{
    
    
				vic[i] = x;
				return true;
			}
		}
	}
	return false;
}
int main()
{
    
    
	//freopen("Input.txt", "r", stdin);
	//freopen("Output.txt", "w", stdout);
	memset(vic, -1, sizeof(vic));
	memset(rel, 0, sizeof(rel));
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s1[i];
	for (int i = 0; i < m; i++)
		cin >> s2[i];
	for (int i = 0; i < n; i++)
	{
    
    
		q1[i] = s1[i][0] - '0' + s1[i][1] - '0' + s1[i][2] - '0';
		h1[i] = s1[i][3] - '0' + s1[i][4] - '0' + s1[i][5] - '0';
	}
	for (int i = 0; i < m; i++)
	{
    
    
		q2[i] = s2[i][0] - '0' + s2[i][1] - '0' + s2[i][2] - '0';
		h2[i] = s2[i][3] - '0' + s2[i][4] - '0' + s2[i][5] - '0';
	}
	for (int i = 0; i < n; i++)
	{
    
    
		for (int j = 0; j < m; j++)
		{
    
    
			if (q1[i] == h2[j])
			{
    
    
				rel[i][j] = 1;
				AT[i][j] = 1;
			}
			if (h1[i] == q2[j])
			{
    
    
				rel[i][j] = 1;
				TA[i][j] = 1;
			}
		}
	}
	int max = 0;
	for (int i = 0; i < n; i++)
	{
    
    
		memset(memory, 0, sizeof(memory));
		if (f(i))max++;
	}
	cout << max << endl;
	for (int i = 0; i < m; i++)
	{
    
    
		if (vic[i] != -1)
		{
    
    
			if (AT[vic[i]][i] == 1)
				cout << "AT " << s1[vic[i]] << " " << s2[i] << endl;
			else if (TA[vic[i]][i] == 1)
				cout << "TA " << s2[i] << " " << s1[vic[i]] << endl;

		}

	}
	return 0;
}
/*2 2
123456 111222
141204 555000*/

There was no A in this question during the competition, mainly because Hungary didn't remember it well and needed more training.

to sum up

The thinking of this team competition is a bit messy, the template questions are not memorized, the reading is still too slow, and English reading ability needs to be strengthened. Come on! ! !

Guess you like

Origin blog.csdn.net/rookie636/article/details/108181081