2013 4th C/C++ Group A Blue Bridge Cup Provincial Competition Real Questions

Here is the topic column of the Blue Bridge Cup over the years. It will be updated and will release the real questions and answers from previous years. Welcome friends to pay attention to me. Your likes and attention are the best motivation for me! ! !
Update one real question every day, so stay tuned

Lanqiao Cup Past Papers and Detailed Answers


Question 1: Gauss' Diary

Title Description The
great mathematician Gauss has a good habit: keep a diary anyway.
There is a difference in his diary. He never noted the year, month, and day, but instead used an integer instead. For example, after 4210,
people knew that the integer was the date, and it said that day was the day after Gauss was born. day. This may also be a good habit. It reminds the owner all the time: One day has passed, how much time is left to waste?
Gauss was born: April 30, 1777.
In the diary of an important theorem discovered by Gauss, it is marked: 5343, so it can be calculated that the day is: December 15, 1791.
The diary on the day Gauss received his doctorate is marked: 8113
, please calculate the date of Gauss's doctorate.
The format for submitting answers is: yyyy-mm-dd, for example: 1980-03-21

Topic analysis
topic codes



Question 2: Exclusive square number

Title description
Xiao Ming is staring at the number 203879 in a daze.
It turns out, 203879 * 203879 = 41566646641
What is the magic of this? Observe carefully, 203879 is a 6-digit number, and the digits on each of its numbers are different, and there are no digits that make up itself in all the digits after its square.
There is another 6-digit number with such characteristics, please find it out!
Summarize the filtering requirements:
1. 6 positive integers
2. The number on each digit is different
3. Each digit of the square number does not contain any constituent digits of the original number The
answer is a 6-digit positive integer.
Topic analysis
topic codes



Question 3: Revitalizing China

Topic description
Xiao Ming participated in the school's fun sports meet, one of which is: jumping grid.
Draw some grids on the ground, and write a word in each grid, as shown below: (also see p1.jpg)
Starting from me, starting from me, starting
from revitalizing,
starting from revitalizing,
starting from revitalizing the Chinese
competition, first stand in the upper left corner In the grid where the word "from" is written, you can jump to the adjacent grid horizontally or vertically, but not to the diagonal grid or other positions. Always jump to the end of the word "华".
The route requested to be skipped just constitutes the phrase "starting from me to revitalize China."
Please help Xiaoming calculate how many possible jumping routes he has?
Topic analysis
topic codes



Fourth question: Inverted price tag

Title description
Xiao Li’s store specializes in sample TVs that are off the shelves in other stores. It can be called a sample TV store.
The price is 4 digits (that is, thousands of yuan).
In order to make the price clear and convenient, Xiao Li used a pre-made price tag similar to a digital tube, as long as he painted the numbers with a colored pen (see p1.jpg).
This kind of price tag has a characteristic, for some figures, it is reasonable to look at it backwards. For example: 1 2 5 6 8 9 0 is all right. In this way, if the brand hangs upside down, it may completely change to another price. For example: 1958 upside down is: 8561, which is a few thousand yuan off!!
Of course, in most cases, you can’t read it backwards, for example, 1110 It cannot be reversed, because 0 cannot be used as the starting number.
One day, the tragedy finally happened. A clerk accidentally hung up two price tags in the store. And the TV sets of these two price brands have been sold!
Fortunately, the price difference is not big. One of the price tags lost more than 200, while the other price tag earned more than 800. All together, it made more. 558 yuan.
Please calculate based on this information: What is the correct price of the price tag that lost money?
Insert picture description here

Topic analysis
topic codes



Question 5: Prefix judgment

Title description The
following code determines whether the string pointed to by needle_start is the prefix of the string pointed to by haystack_start, if not, it returns NULL.
For example: "abcd1234" contains "abc" as a prefix

char* prefix(char* haystack_start, char* needle_start)
{
    
    
	char* haystack = haystack_start;
	char* needle = needle_start;

	
	while(*haystack && *needle){
    
    
		if(______________________________) return NULL;  //填空位置
	}
	
	if(*needle) return NULL;
	
	return haystack_start;
}

Topic analysis
topic codes



Question 6: Reverse Polish expression

Title description
Normal expressions are called infix expressions. The operator is in the middle, which is mainly for human reading, and it is not convenient to solve by machine.
For example: 3 + 5 * (2 + 6)-1
Moreover, it is often necessary to use parentheses to change the order of operations.
On the contrary, if it is expressed by inverse Polish expression (prefix expression), the above formula is expressed as:
-+ 3 * 5 + 2 6 1 The
parentheses are no longer needed, and the machine can solve it easily by recursive method.
For simplicity, we assume:

  1. Only +-* three operators
  2. Each operand is a non-negative integer less than 10

The following program evaluates an inverse Polish representation string.
The return value is a structure: the first element represents the evaluation result, and the second element represents the number of characters it has parsed.

struct EV
{
    
    
	int result;  //计算结果 
	int n;       //消耗掉的字符数 
};

struct EV evaluate(char* x)
{
    
    
	struct EV ev = {
    
    0,0};
	struct EV v1;
	struct EV v2;

	if(*x==0) return ev;
	
	if(x[0]>='0' && x[0]<='9'){
    
    
		ev.result = x[0]-'0';
		ev.n = 1;
		return ev;
	}
	
	v1 = evaluate(x+1);
	v2 = _____________________________;  //填空位置
	
	if(x[0]=='+') ev.result = v1.result + v2.result;
	if(x[0]=='*') ev.result = v1.result * v2.result;
	if(x[0]=='-') ev.result = v1.result - v2.result;
	ev.n = 1+v1.n+v2.n;

	return ev;
}

Topic analysis
topic codes



Question 7: Wrong ticket

Title description A
certain secret-related unit issued a certain kind of bill, and it must be recovered at the end of the year.
Each ticket has a unique ID number. The ID numbers of all bills throughout the year are consecutive, but the starting number of the ID is randomly selected.
Due to the negligence of the staff, an error occurred when entering the ID number, which caused one ID to be out of number and another to be duplicated.
Your task is to find out the ID of the broken number and the ID of the repeated number through programming.
Assume that a broken number cannot occur between the largest and smallest numbers.
The program is required to first input an integer N (N<100) to indicate the number of data rows.
Then read in N rows of data.
The length of each line of data varies, and is a number (not more than 100) positive integers (not more than 100000) separated by spaces.
Each integer represents an ID number.
The program is required to output one line, containing two integers mn, separated by spaces.
Among them, m represents the broken ID, n represents the repeated ID

For example:
user input:
2
5 6 8 11 9
10 12 9

The program output:
7 9

Another example:
user input:
6
164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
172 189 127 107 112 192 103 131 133 169 158
128 102 110 148 139 157 140 195 197
185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119

The program output:
105 120

Resource agreement:
Peak memory consumption <64M
CPU consumption <1000ms

Topic analysis
topic codes



Question 8: Unavailable amount

Title description
Xiao Ming opened a candy store. He is ingenious: pack fruit candy into two packs of 4 and 7 pieces. Candies cannot be sold unpacked.
When a child comes to buy sweets, he uses these two packages to combine. Of course, some candies cannot be combined, such as 10 candies.
You can test it with a computer. In this packaging case, the maximum unavailable quantity is 17. Any number greater than 17 can be combined with 4 and 7.
The requirement of this question is to find the largest number that cannot be combined when the quantities of two packages are known.

Input:
Two positive integers, indicating the number of sugar in each package (not more than 1000)

Required output:
a positive integer, indicating the maximum number of sugars that cannot be bought

No need to consider unsolvable situations

For example:
User input:
4 7 The
program should output:
17

Another example:
User input:
3 5 The
program should output:
7
Question analysis
question code



Question 9: Cut the grid

Title description
As shown in Figure p1.jpg, some integers are filled in the 3 x 3 grid.
We cut along the red line in the picture, and got two parts, the sum of each part is 60.
The requirement of this question is to ask you to program to determine whether the integer in the given mxn grid can be divided into two parts so that the sum of the numbers in these two areas is equal.
If there are multiple solutions, please output the minimum number of grids contained in the area containing the top left grid.
If it cannot be divided, 0 is output

Program input and output format requirements: the
program first reads two integers mn, separated by spaces (m,n<10) to
indicate the width and height of the table.
Next are n rows, each with m positive integers, separated by spaces. Each integer is not greater than 10000. The
output of the program: In all the solutions, the smallest number of grids that may be contained in the partition in the upper left corner is included.

For example:
user input:
3 3
10 1 52
20 30 1
1 2 3

The program output:
3

Another example:
user input:
4 3
1 1 1 1
1 30 80 2
1 1 1 100

The program output:
10

(See p2.jpg)

Resource agreement:
peak memory consumption <64M
CPU consumption <5000ms

Insert picture description here
Insert picture description here

Topic analysis
topic codes



Question 10: Minister’s travel expenses

Title Description
Long ago, Kingdom T was prosperous. In order to better manage the country, the kingdom has built a large number of expressways to connect the capital and major cities in the kingdom.
In order to save money, the ministers of Country T have formulated an excellent construction plan after thinking, so that any big city can be reached directly from the capital or indirectly through other big cities. At the same time, if you don't repeatedly pass through big cities, the plan from the capital to each big city is unique.
J is an important minister of country T. He patrols between major cities to understand the people's sentiments. Therefore, non-stop from one city to another has become the most common thing J does. He has a purse to store travel expenses between cities.
The clever J found that if he does not stop to repair in a certain city, the travel expenses he spends during the continuous journey are related to the distance he has traveled, and he is walking the kilometer from the xth kilometer to the x+1th kilometer. Medium (x is an integer), his travel expenses are x+10 so much. In other words, it costs 11 to walk 1 kilometer and 23 to walk 2 kilometers.
Minister J wanted to know: What is the maximum amount of travel expenses that he might spend when starting from a certain city without taking a break and arriving in another city?
Input format:
The first line of input contains an integer n, which represents the number of
cities in Kingdom T including the capital. The cities are numbered sequentially starting from 1, and the first city is the capital.
The next n-1 lines describe the highways in country T (the highways in country T must be n-1).
Each line has three integers Pi, Qi, Di, indicating that there is a highway between city Pi and city Qi. The length is Di kilometers.
Output format:
output an integer, indicating how much the minister J spends the most on the road.

Sample input:
5
1 2 2
1 3 1
2 4 5
2 5 4

Sample output:
135

Example explanation:
Minister J will spend 135 toll to travel from city 4 to city 5.

Consider supporting larger data scales as much as possible based on resource constraints.

Resource agreement:
peak memory consumption <64M
CPU consumption <5000ms

Topic analysis
topic codes



Guess you like

Origin blog.csdn.net/kiwi_berrys/article/details/111462107