2016 6th Blue Bridge Cup National Competition Problem Solution

The scores for the following questions are: 15, 35, 25, 47, 79, 99

Question 1: One step away (5min)

  • Waking up from a coma, Xiao Ming finds himself locked in an abandoned minecart on Planet X. The minecart is parked on a straight, abandoned track. In front of him are two buttons with "F" and "B" written on them.
  • Xiao Ming suddenly remembered that these two buttons could control the minecart to move forward and backward on the track. Press F to advance 97 meters. Press B to go back 127 meters.
  • Through the dim light, Xiao Ming saw that there was a surveillance probe 1 meter in front of him. He had to find a way to get the minecart parked just below the camera to get a chance to get help from his companions.
    Perhaps, by manipulating F and B multiple times.
  • The power on the minecart is not enough, and the yellow warning light is blinking silently... Every time you perform an F or B operation, a certain amount of energy is consumed.
  • Xiao Ming quickly calculated how many operations it would take to park the minecart exactly 1 meter ahead.
  • Please fill in the minimum number of operations required to achieve the goal.
  • Note that what needs to be submitted is an integer, do not fill in any irrelevant content (such as: explanation, etc.)
  • Answer: 97
  • Idea: double cycle, violent solution
    insert image description here
  • Idea: Extended Euclidean
    insert image description here

Question 2: Making squares

把0~9这10个数字,分成多个组,每个组恰好是一个平方数,这是能够办到的。 比如:0, 36, 5948721

再比如: 1098524736 1, 25, 6390784 0, 4, 289, 15376 等等…

注意,0可以作为独立的数字,但不能作为多位数字的开始。 分组时,必须用完所有的数字,不能重复,不能遗漏。

如果不计较小组内数据的先后顺序,请问有多少种不同的分组方案?

注意:需要提交的是一个整数,不要填写多余内容。

Question 3: Chess Transposition (43min)

There are n pieces A, n pieces B, lined up on the board. They are separated by a space, represented by ".", for example:

AAA.BBB

Now all A and B pieces need to be swapped. The rules for moving pieces are:
1. Piece A can only move to the right, piece B can only move to the left.
2. Each piece can be moved to the adjacent empty space.
3. Each pawn can jump over a different pawn to fall into the vacant position (A jumps over B or B jumps over A).

AAA.BBB can move:

Move A ==> AA.ABBB

Move B ==> AAAB.BB

Example of jumping away: AA.ABBB ==> AABA.BB

The following program completes the function of AB transposition, please read and analyze the source code carefully, and fill in the missing content in the underlined part

#include <stdio.h>  
#include <string.h>  
  
void move(char* data, int from, int to)  
{  
    data[to] = data[from];  
    data[from] = '.';  
}  
  
int valid(char* data, int k)  
{  
    if(k<0 || k>=strlen(data)) return 0;  
    return 1;  
}  
  
void f(char* data)  
{  
    int i;  
    int tag;  
    int dd = 0; // 移动方向  
  
    while(1){  
        tag = 0;  
        for(i=0; i<strlen(data); i++){  
            if(data[i]=='.') continue;  
            if(data[i]=='A') dd = 1;  
            if(data[i]=='B') dd = -1;  
  
            if(valid(data, i+dd) && valid(data,i+dd+dd)   
            && data[i+dd]!=data[i] && data[i+dd+dd]=='.'){   
            //如果能跳...   
                move(data, i, i+dd+dd);  
                printf("%s\n", data);  
                tag = 1;  
                break;  
            }  
        }  
  
        if(tag) continue;  
  
        for(i=0; i<strlen(data); i++){  
            if(data[i]=='.') continue;  
            if(data[i]=='A') dd = 1;  
            if(data[i]=='B') dd = -1;             
  
            if(valid(data, i+dd) && data[i+dd]=='.'){   
            // 如果能移动...  
                if(( ______________________) continue;  //填空位置   
                move(data, i, i+dd);  
                printf("%s\n", data);  
                tag = 1;  
                break;  
            }  
        }  
  
        if(tag==0) break;                     
    }  
}  
  
int main()  
{  
    char data[] = "AAA.BBB";      
    f(data);  
    return 0;  
}  
  • Answer: ( i+dd+dd+dd= =6||i+dd+dd+dd==0 )&&data[i]!=data[i+dd+dd] (my, inference)
  • valid(data,i-dd)&&valid(data,i+dd+dd)&&data[i-dd]!=data[i]&&data[i+dd+dd]!=data[i](他人的)
  • Ideas:
  • 首先把那一行注释掉,发现停止在一段,推测,前方有一步交换错误。
    
  • 由题意易知,BA,或者,AB不可跳,且可改变位置在交换处
    
  • 可得到两处交换点故,将其更改做限制在看
    

insert image description here

Question 4: Robot Tower (1h)

Planet X's robot show cheerleaders come in two outfits, A and B. Their performance this time is to build a robot tower.

similar:

A
BB
ABA
AABB BBBAB ABABBA
team tower rules are: A can only stand on the shoulders of AA or BB. B can only stand on the shoulders of AB or BA.


Your task is to help the cheerleaders calculate how many towers can be formed given the number of A and B.

Enter a line of two integers M and N, separated by spaces (0<M, N<500), respectively indicating the number of people A and B, to ensure the rationality of the number of people.

It is required to output an integer, indicating the number of patterns that can be generated.

For example:
User input:
1 2

The program should output:
3

Another example:
user input:
3 3

The program should output:

4

  • Idea: First, find the number of layers t according to m+n (the number of layers of the triangle does not exceed 50 layers)
  • Then deduce all the cases from bottom to top (moving return), and each time judge whether the obtained triangle satisfies the number of A and B given on the title
  • Finally, to accumulate su; (recursion, DP, deep search)
#include<bits/stdc++.h>
using namespace std;
int a[1000],b[1000];
int n,m,t,su=0;
int ac(int b[],int ee,int cc)//a[][max]
{
	int te=0,bb=ee,c=cc;
	for(int i=t-1;i>=1;i--)
	{
		for(int j=1;j<=i;j++)
		{
			if(bb<0||c<0)
			{
				te=1;
				break;
			}
			if(b[j]==b[j+1])
			{
				b[j]=1;bb--;
			}
			else
			{
				b[j]=0;c--;
			} 
		}
	}
	if(te==0&&bb==0&&c==0) return 1;
	else return 0;
}
int bc(int a[ ],int l,int n,int m)
{
	if(m<0||n<0) return 0;
	if(l==t+1)
	{
		for(int i=1;i<=t;i++)
		{
			b[i]=a[i];
		}//cout<<n<<" "<<m<<endl;
		if(ac(b,n,m)==1)
		{
			su++;//
		}
		return 0;
	}
	a[l]=1;
	//弄了半天 
	a[l]=1;///
	bc(a,l+1,n-1,m);//
	a[l]=0; //
	bc(a,l+1,n,m-1);//m-1代入,但是m的值并没有变哟
//	m=m+1;a[l]=1;
}
int main()
{
	cin>>n>>m;
	for(int i=1;;i++)
	{
		if(n+m==i*(i+1)/2)
		{
			t=i;
			break;
		}
	}
	memset(a,0,sizeof(0));
 	bc(a,1,n,m);
	cout<<su;
	return 0;
}

Question 5: Square Dance

The Civic Square in LQ City is a polygon covered with marble floor tiles.

The floor tiles are square and square, like axis paper.
Taking the point where four bricks meet as the origin, the two sides of the floor tile are two positive directions, and the side length of a brick is the unit length of the horizontal and vertical coordinates, then all the points whose horizontal and vertical coordinates are integers are four. The intersection of the bricks (if inside a square).

The bricks of the square are monotonous and uninteresting, but they provide an excellent reference for the citizens who dance in the square. Every evening, a large number of people come to dance.
The dancer will choose a complete brick to dance every time, two people will not choose the same brick, if a brick is missing or incomplete on the edge of the square, no one will choose this brick.
(For an example of a square shape, refer to [Figure 1.png])

Now, tell you the shape of the square, please help the mayor of LQ to calculate the maximum number of citizens who can dance in the square at the same time.

[Input format]
The first line of input contains an integer n, indicating that the square is n-sided (and therefore has n vertices).
The next n lines, each with two integers, represent the coordinates of each vertex of the n-gon in turn (that is, the corners of the square edge are all on the top corner of the brick. The data guarantees that the square is a simple polygon.

[Output format]
Output an integer, indicating how many citizens can dance in the square at most.

【Sample input】
5
3 3
6 4
4 1
1 -1
0 4

[Sample output]
7

[Example description]
The square is shown in Figure 1.png. There are 7 complete floor tiles, so at most 7 citizens can dance together.

[Data scale and convention]
For 30% of the data, n should not exceed 100, and the absolute values ​​of the abscissa and ordinate should not exceed 100.
For 50% of the data, n does not exceed 1000, and the absolute values ​​of the horizontal and vertical coordinates do not exceed 1000.
For 100% data, n does not exceed 1000, and the absolute values ​​of the horizontal and vertical coordinates do not exceed 100,000,000 (one hundred million).

Resource convention:
peak memory consumption < 256M
CPU consumption < 1000ms

Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.

Note: The main function needs to return 0
Note: Only use the ANSI C/ANSI C++ standard, do not call special functions that depend on the compilation environment or operating system.
Note: All dependent functions must be explicitly #included in the source file, and common header files cannot be omitted through project settings.

When submitting, take care to select the desired compiler type.

insert image description here

Question 6: Determine the number of spanning trees

Given an n m lattice graph, it contains n m vertices with n rows and m columns, and there is an edge between adjacent vertices.
[Figure 1.png] gives an example of a 3*4 lattice map.

If some vertices and their adjacent edges are deleted in the graph, as shown in the figure above, after deleting the vertices in the 2nd row, 3rd column and 3rd row and 1st column, as shown in [Figure 2.png].

The spanning tree of a graph refers to all vertices and some of the edges in the graph, so that there is a unique path composed of edges between any two vertices. If two spanning trees contain different edges, they are considered to be different. There are 31 different spanning trees in the above figure, of which 10 are not selected for edge a, and 21 are selected for edge a.
Given information about the vertices retained in a lattice graph, count how many different spanning trees there are in the graph.

【Input format】
The first line of the input contains two integers n, m, separated by spaces, which represent the number of rows and columns of the grid point graph.
Next n lines, each line contains m letters (no separator characters in between), each letter must be uppercase E or uppercase N, E indicates that the corresponding vertex exists, and N indicates that the corresponding vertex does not exist. At least one vertex is guaranteed to exist.

【Output format】
Output one line, including an integer, which indicates the number of spanning trees. The answer can be large, you just need to calculate the remainder of dividing the answer by 1000000007.

【Sample input】
3 4
EEEE
EENE
NEEE

[Sample output]
31
insert image description hereinsert image description here

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326625994&siteId=291194637