Summary of C++ Real Questions in Group B of the 7th Blue Bridge Cup National Competition in 2016

1. One step away

Waking up from a coma, Xiao Ming found himself locked in an abandoned minecart on Planet X.
The minecart was parked on a straight, abandoned track.
In front of him are two buttons, written "F" and "B" respectively.

Xiao Ming suddenly remembered that these two buttons could control the minecart to move forward and backward on the track.
Press F, it will advance 97 meters. Press B to go back 127 meters.
Through the dim light, Xiao Ming saw that there was a surveillance probe just 1 meter in front of him.
He must try to make the minecart stop just below the camera before he has a chance to get help from his companions.
Perhaps it can be done through multiple operations of F and B.

The power on the minecart is not enough, the yellow warning light is flashing silently...
every time you perform F or B operation, a certain amount of energy will be consumed.
Xiao Ming quickly calculated how many operations it would take to park the minecart exactly 1 meter away in front of him.

Please fill in the minimum number of operations required to achieve the goal.

2. Square number

Divide the 10 numbers from 0 to 9 into multiple groups, each of which happens to be a square number. This can be done.
For example: 0, 36, 5948721

Another example:
1098524736
1, 25, 6390784
0, 4, 289, 15376
and so on...

Note that 0 can be used as an independent number, but not as the beginning of multiple digits.
When grouping, all numbers must be used up, and cannot be repeated or omitted.

If the order of the data in the smaller groups is not counted, how many different grouping schemes are there?

3. Pawn transposition

There are n chess pieces A and n chess pieces B in a row on the chessboard.
There is a space between them, which is represented by ".", such as:

AAA.BBB

Now all A pieces and B pieces need to exchange positions.
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 an adjacent empty position.
  3. Each piece can skip a different piece and fall into the empty position (A skips B or B skips 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;
}

4. Robot Tower

There are two kinds of costumes for the robot performance cheerleader of X planet, A and B.
What they performed this time was to build a robot tower.

similar:

​ A
​ B B
A B A
A A B B
B B B A B
A B A B B A

The tower building rules in the team 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 cheerleader to calculate how many kinds of towers can be formed given the number of people A and B.

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

An integer is required to indicate the number of patterns that can be produced.

E.g:

User input:

1 2

The program should output:

3

Another example:

User input:

3 3

The program should output:

4

5. Square dance

The citizen square in LQ city is a polygon, and the square is covered with marble floor tiles.

The floor tiles are laid squarely, just like coordinate paper.
Taking the point where four bricks meet as the origin, the two sides of the floor tile are in two positive directions, and the side length of a brick is the unit length of the abscissa and ordinate, then all the points whose abscissa and ordinate are integers are four. The intersection of the bricks (if in the square).

The square bricks are monotonous and boring, but they provide an excellent reference for the citizens who dance in the square. Every evening, a large number of citizens come to dance.
Dancers will choose a complete brick to dance every time. Two people will not choose the same brick. If a brick is missing corners or incomplete edges on the edge of the square, no one will choose this brick.
(For examples of square shapes, please refer to [Figure 1.png])

Now, tell you the shape of the square, please help the mayor of LQ calculate how many citizens 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 (so there are n vertices).

The next n rows, each with two integers, represent the coordinates of each vertex of the n-sided polygon in turn (that is, the corners of the square edge are on the top corners 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

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

img

6. Spanning Tree

Given a lattice point graph of n m, it contains n rows and m columns, a total of n m vertices, and there is an edge between adjacent vertices.
[Picture 1.png] An example of a 3*4 grid graph is given.

Insert picture description here

If some vertices and their adjacent edges are deleted in the graph, after deleting the vertices in the second row and the third column and the third row and the first column, as shown in [Figure 2.png].

Insert picture description here

The spanning tree of a graph includes 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 different. There are 31 different spanning trees in the above figure, of which 10 are not selected for side a, and 21 are selected for side a.
Given the information of the vertices retained in the lattice graph, please calculate how many different spanning trees there are in the graph.

[Input format] The first line of input contains two integers n, m, separated by spaces, indicating the number of rows and columns of the grid graph.

In the next n lines, there are m letters in each line (there is no separating character in the middle), and each letter must be uppercase E or uppercase N. E means the corresponding vertex exists, and N means the corresponding vertex does not exist. Ensure that there is at least one vertex.

[Output format] Output one line, including an integer, indicating the number of spanning trees. The answer may be large, you only need to calculate the remainder of the answer divided by 1000000007.

【Sample input】 3 4

EEEE

ONE

NEEE

【Sample output】 31

Guess you like

Origin blog.csdn.net/weixin_44723496/article/details/109407635