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

1. The puzzle of points

Xiao Ming opened an online shop to sell wind chimes. There are 3 brands: A, B, C.
In order to promote sales, each item will return a fixed point.
Xiao Ming received three orders on the first day of opening: The
first: 3 A + 7 B + 1 C, a total of 315 points: The
second: 4 A + 10 B + 1 C, a total of return Points: 420 The
third pen: A + B + C, total points are returned...

Can you figure out how many points need to be rebated for the third order?

2. Perfect square

If some squares with different sides can fit into a larger square, it is called a perfect square.
In history, it took a long time for people to find a number of perfect squares. For example: the following 22 squares
2 3 4 6 7 8 12 13 14 15 16 17 18 21 22 23 24 26 27 28 50 60
are combined as shown in [Figure 1.png], which is a solution. At this time, what is
close to the upper edge is: 60 50 and what is
close to the lower edge is: 26 28 17 21 18
22 perfect squares. There are 8 kinds of perfect squares. The following combination is another one:
2 5 9 11 16 17 19 21 22 24 26 30 31 33 35 36 41 46 47 50 52 61
If you tell you that the plan is close to the upper edge, from left to right: 47 46 61.
Can you calculate which squares are next to the bottom edge?

img

3. Linked accounts

In order to increase the anti-corruption efforts, a special police detachment in a certain place launched an investigation into a number of bank accounts.
If there is a transfer between the two accounts, it is considered to be related. If there is a correlation between a and b, and there is a correlation between b and c, it is considered that there is a correlation between a and c.
For the n accounts (numbered 0 to n-1) within the scope of the investigation, the police already know of m direct associations caused by transfers.
Now I want to know any given two accounts and find out if they are related. There is an associated output of 1, and no associated output of 0

Xiao Ming gave the following solutions:

4. Ciphertext search

Holmes received a document from Star X, all in lowercase letters.
His assistant provided another piece of information: many password lists of length 8.
Holmes discovered that these passwords had been shuffled and hidden in the previous data.
Please write a program to search for possible hidden password locations from the first document. Consider all possible permutations of passwords.

enter

The first line: a string s, all composed of lowercase letters, and the length is less than 1024*1024

The next line is an integer n, which means that there are n lines of passwords, 1<=n<=1000
followed by n lines of strings, which are all lowercase letters, and the length is 8

Output:

An integer representing the total number of matches in s for all permutations of each row of passwords.

E.g:

User input:

aaaabbbbaabbcccc
2
aaaabbbb
abcabccc

The program should output:

4
This is because: the first password is matched 3 times, and the second password is matched 1 time, a total of 4 times.

5. Resident Assembly

The residents of Lanqiao Village live on the edge of a highway. The length of the highway is L. The position of each family is calculated by the distance between the family and the starting point of the highway. The distance between the i-th household and the starting point is di.
Every year, Lanqiao Village holds a rally. This year, due to the large population in the village, the village committee decided to hold rallies in four places, three of which are located in the middle of the highway and one at the end of the highway.
It is known that every family will go away from the starting point of the road to participate in the rally, and the travel cost of participating in the rally is the product of the number of people in the family ti and the distance.
Given the location di and the number of people ti of each household, please find the best place for the village committee to hold the meeting: p1, p2, p3, p4 (p1<=p2<=p3<=p4=L), so that all in the village The cost of the person’s journey is minimal.

[Input format]

The first line of input contains two integers n, L, which represent the number of households in Lanqiao Village and the length of the road.
In the next n lines, each line contains two integers di, ti, which respectively represent the distance of the i-th family from the starting point of the road and the number of people in the family.

[Output format]

Output a line containing an integer that represents the total cost of all people in the village.

【Sample input】

6 10
1 3
2 2
4 5
5 20
6 5
8 7

[Sample output]

18

[Sample description]

For gatherings in 4 places from the starting point 2, 5, 8, 10, the distances required by the 6 families to walk are 1, 0, 1, 0, 2, 0, and the total distance cost is 1 3+0 2+1 5+0 20+2 5+0 7=18.

6. Model coloring

In the movie "Big Hero 6", Xiaohong can use his miniature robots to form various shapes.
Now he used his miniature robot to make a big toy for children to play with. In order to be more beautiful, he decided to dye the toy.
Xiaohong's toy consists of n spherical end points and m segments connecting the edges between these end points. The figure below shows a toy consisting of 5 ball-shaped endpoints and 4 sides, which looks very much like a molecular ball-and-stick model.
Because Xiaohong’s miniature robots are very flexible, these spherical endpoints can move arbitrarily in space, and the edges connecting two adjacent spherical endpoints can be arbitrarily stretched, so that a toy can be transformed into different shapes. In the process of transformation, the edges will neither increase nor decrease.
Xiaohong wants to dye his toys no more than k colors so that the toys look different. If the change can make the toy become the same color pattern, it is considered to be essentially the same coloring. Now Xiaohong wants to know how many different dyeings are possible.

[Input format]

The first line of input contains three integers n, m, k,
which respectively represent the number of endpoints, the number of sides and the number of colors that the small macro may use on the toy of the small macro. The endpoints are numbered from 1 to n.
In the next m rows, there are two integers a, b in each row, indicating that there is an edge between the a-th endpoint and the b-th endpoint. The input guarantees that no two identical edges will appear.

[Output format]

One line is output, indicating the number of dyeing schemes that are essentially different. Since the number of plans may be large, please enter the remainder of the number of plans divided by 10007.

【Sample input】

3 2 2
1 2
3 2

[Sample output]

6

[Sample description]

Let (a, b, c) denote that the first end point is dyed as a, the second end point is dyed as b, and the third end point is dyed as c, then the following 6 essentially different dyeings: (1, 1, 1), (1, 1, 2), (1, 2, 1), (1, 2, 2), (2, 1, 2), (2, 2, 2).
And (2, 1, 1) and (1, 1, 2) are essentially the same, (2, 2, 1) and (2, 1, 2) are essentially the same.

img

Guess you like

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