Summary of C++ Real Questions in Group B of the Ninth Blue Bridge Cup National Competition in 2018

1. Change the zero bill

The denominations of the banknotes of Planet X are only: 100 yuan, 5 yuan, 2 yuan, 1 yuan, a total of 4 types.
Xiao Ming traveled to X Star, and he only had two 100 yuan X Star coins in his hand, which was too inconvenient. He happened to pass by X Star Bank to change change.
Xiao Ming is a bit obsessive-compulsive. He insists that the number of 2 yuan in the 200 yuan exchanged note is exactly 10 times the number of 1 yuan, and the
rest are of course 5 yuan denominations.

The bank staff is a bit embarrassed, can you help figure out: on the premise of meeting Xiao Ming's requirements, at least how many banknotes should be exchanged for him?
(5 yuan, 2 yuan, 1 yuan denominations must be available, not 0)

Note that what needs to be submitted is an integer, do not fill in any extra content.

2. Laser style

In order to increase the atmosphere, the grand festival of Planet X uses 30 optical devices lined up to cast beams of light into space.
It was discovered during installation and debugging that for some unknown reason, two adjacent lasers could not be turned on at the same time!
The king would like to know how many laser effects can be produced with this kind of bug at present?

Obviously, if there are only 3 machines, there can be a total of 5 styles, namely:
all closed (sorry, at this time silent is better than sound, this is also one type)
, a total of 3 types
, two machines , only one type

30 is not good enough, the king has to ask you for help.

An integer is required to indicate the number of patterns that can be formed by 30 lasers.

Note, only submit a whole number, do not fill in any extra content.

3. Gray code

Gray code is a binary representation of n bits.
Different from ordinary binary representation, it requires only one digit to be different between two adjacent numbers.
The first and last two numbers are also required to have a difference of only 1 digit.

There are many algorithms to generate Gray codes. The following is the more common one:
start generating from the code all 0s.
When the odd number is generated, only the last digit of the current number is changed (0 changes to 1, 1 changes to 0).
When the even number is generated, first find the rightmost 1 and change the number on its left.
The 4-bit Gray code sequence generated by this rule is as follows:
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000

The following is the implementation code, carefully analyze the logic, and fill in the missing code in the underlined part. (Answer: a^((a&(-a))<<1))

Regardless of the complexity of the code turning around, in fact, the value of a is the Gray code sequence. Here is the function of a&-a: a number consisting of consecutive 0s plus a 1 in the low digits of a binary number, such as a=12 (1100) , There are two consecutive 0s in the low bit, then a&-a=4 (100). The question requires changing the number to the left of the rightmost 1 when the even number is generated, that is, 0001->0011, 0010->0110, 0111->0101, 0100->1100, 1101->1111, 1110->1010, 1011->1001, then a&-a works, we find the low-order continuous 0 plus a number consisting of 1, let it move one bit to the left, and then XOR with a, 1 1=0, 1 0= 1. In this way, the goal is achieved.

#include <stdio.h>
void show(int a,int n){
	int i;
	int msk = 1;
	for(i=0; i<n-1; i++) msk = msk << 1;
	for(i=0; i<n; i++){
		printf((a & msk)? "1" : "0");
		msk = msk >> 1;
	}
	printf("\n");
} 
void f(int n){
	int i;
	int num = 1;
	for(i=0; i<n; i++) num = num<<1;
	int a = 0;
	for(i=0; i<num; i++){
		show(a,n);
		if(i%2==0){
			a = a ^ 1;
		}
		else{
			a = _________________________ ; //填空
		}
	}
}
int main(){
	f(4);
	return 0;
}

4. Adjust the watch

Xiao Ming bought a high-end, high-end electronic watch, and he is about to adjust the time.
In the M78 Nebula, the unit of measurement of time is different from that on Earth. An hour in the M78 Nebula has n minutes.
Everyone knows that the watch has only one button to increase the current number by one. When adjusting the minutes, if the currently displayed number is 0, it will change to 1 when you press the button, and it will change to 2 when you press it again. If the current number is n-1, it will become 0 after pressing it once.
As a patient with obsessive-compulsive disorder, Xiao Ming must adjust the time of his watch. If the time on the watch is 1 more than the current time, you have to press the plus one button n-1 times to return to the correct time.
Xiao Ming thought, if the watch can add another button, it means adding k to the current number...
He wants to know that if there is this +k button, press the button according to the optimal strategy to adjust from any minute to another The maximum number of times to press any one minute.
Note that when you press the +k button, if the number after adding k exceeds n-1, n will be modulo n.
For example, when n=10 and k=6, assuming that the current time is 0, press the +k button twice to adjust to 2.

"Input format"

Two integers n, k in a row have the same meaning as the title.

"Output Format"

One integer
per line means: press the key according to the optimal strategy, and the maximum number of times to be pressed from one time to another.

"Sample Input"

5 3

"Sample output"

2

"Sample explanation"

If the time is correct, press 0 times. Otherwise, the relationship between the number of times to be pressed and the operation series is as follows:
1: +1
2: +1, +1
3: +3
4: +3, +1

"data range"

For 30% of data 0 <k <n <= 5
For 60% of data 0 <k <n <= 100
For 100% of data 0 <k <n <= 100000

Resource agreement:

Peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Please output strictly according to the requirements, and don't superfluously print the extra content like: "Please input...".

5. Build blocks

Xiao Ming is very interested in building blocks. His building blocks are all regular cubes of the same size.
When building blocks, Xiao Ming chose m blocks as the foundation, lined them up on the table, leaving no gaps in between, and called it the 0th floor.
Later, Xiao Ming can place the first layer, the second layer,..., up to the nth layer. Three rules must be followed when placing blocks:

Rule 1: Each building block must be placed directly above a certain building block and aligned with the building blocks of the next layer;
Rule 2: Building blocks in the same layer must be placed continuously without any gaps between them;
Rule 3: Xiao Ming Blocks cannot be placed where you don’t like.

Among them, the locations that Xiao Ming doesn't like are all marked on the drawings. There are n lines in the drawing, and each line from bottom to top corresponds to the first to nth levels of the building block. There are m characters in each line, the characters may be'.' or'X', where'X' means that this position is not liked by Xiao Ming.
Now, Xiao Ming wants to know how many ways there are to place blocks. He found you who participated in the Blue Bridge Cup to help him calculate the answer.
Since this answer may be large, you only need to answer the result of this answer modulo 1000000007 (billion and seven).
Note: Putting nothing on the foundation is also considered as a kind of plan.

[Input format]

The first line of input data has two positive integers n and m, which represent the size of the drawing.
The following n lines, each line has m characters, used to describe the drawing. Each character can only be'.' or'X'.

[Output format]

Output an integer, representing the result of the answer modulo 1000000007.

【Sample input 1】

2 3
…X
.X.

[Sample output 1]

4

[Sample description 1]

Successful placements (where O means placing blocks):
(1)
…X
.X.
(2)
…X
OX.
(3)
OX
OX.
(4)
…X
.XO

【Sample input 2】

3 3
…X
.X.

[Sample output 2]

16

[Data size agreement]

For 10% data, n=1, m<=30;
for 40% data, n<=10, m<=30;
for 100% data, n<=100, m<=100.

6. Matrix Summation

After numerous written examinations and interviews, Xiao Ming successfully entered the Macrohard company.
Today, Xiao Ming’s task is to fill up such a table: the
table has n rows and n columns, and the row and column numbers start from 1.
The value of the j-th element in the i-th row is the square of gcd(i, j),
gcd represents the greatest common divisor, and the following are the first four columns of the first four rows of this table:
1 1 1 1
1 4 1 4
1 1 9 1
1 4 1 16

Xiao Ming suddenly had a strange idea. He wanted to know the sum of all the elements in this table.
Because the watch is too large, he hopes to use the power of the computer.

"Input format"

See the question for the meaning of a positive integer n per line.

"Output Format"

A number on a line represents the sum of all elements. Since the answer is relatively large, please output the result after modulo (10^9 + 7) (ie: one billion and seven).

"Sample Input"

4

"Sample output"

48

"data range"

For 30% of the data, n <= 1000
there is 10% of the data, n = 10^5
for 60% of the data, n <= 10^6
for 100% of the data, n <= 10^7

Guess you like

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