The 4th C/C++ Group A Blue Bridge Cup Provincial Competition in 2013

Here is the topic column of the Blue Bridge Cup over the years. It will be updated successively and the real questions and answers of previous years will be released. I welcome you to follow me. Your likes and attention are the best motivation for me! ! !
The real questions are updated every day, so stay tuned

Blue Bridge Cup real questions and detailed answers over the years


Question 1: Gauss's Diary

Topic description
Gauss, a great mathematician, had a good habit: keep a diary anyway.
There is a difference in his diary. He never indicated the year, month, and day, but replaced it with an integer, such as: 4210
Later, people knew that the integer was the date, which indicated the day after Gauss was born. sky. This may also be a good habit. It reminds the owner all the time: the day goes by, how much time is there 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 that Gauss received his doctorate was marked: 8113
Please calculate the year, month, and day when Gauss received his doctorate.
The format of the submitted answer is: yyyy-mm-dd, for example: 1980-03-21

topic analysis
topic code



Question 2: Excluded Squares

Title description
Xiao Ming is staring at the number 203879 in a daze.
It turns out that 203879 * 203879 = 41566646641
What's the magic? Carefully observe, 203879 is a 6-digit number, and the digits on each of its digits are different, and none of the digits that make up its own appear on all digits after it is squared.
There is another 6-digit number with such characteristics, please find it!
Summarize the screening requirements:
1. 6-digit positive integer
2. The number on each digit is different
3. Each digit of its square number does not contain any constituent digits of the original number The
answer is a 6-digit positive integer.
topic analysis
topic code



Topic 3: Revitalize China

Topic description
Xiao Ming participated in the school's fun sports meeting, one of which is: jumping the grid.
There are some grids drawn on the ground, and a word is written in each grid, as shown below: (See also p1.jpg) Start
from me, start from me
, start
from
me
In the grid with the word "from" written on it, you can jump to the adjacent grid horizontally or vertically, but you cannot jump to the diagonal grid or other positions. Have to skip to the end of the word "Hua".
The route to be skipped is exactly what constitutes the phrase "start from me to revitalize China".
Could you please help Xiao Ming to calculate how many possible jumping routes he has?
topic analysis
topic code



Question 4: Upside-down price tags

Topic description
Xiao Li's store specializes in sample TV sets that have been removed from other stores, so it can be called a sample TV store.
The price tag is 4 digits (that is, ranging from thousands of dollars).
In order to make the price clear and convenient, Xiao Li used a prefabricated price tag similar to a digital tube, and just painted the numbers with a color pen (see p1.jpg).
This kind of price tag has a characteristic. For some numbers, it is also a reasonable number in reverse. Such as: 1 2 5 6 8 9 0 can be. In this way, if the brand is hung upside down, it may be completely changed to another price, for example: 1958 hanging upside down is: 8561, which is a few thousand yuan difference!!
Of course, in most cases, it cannot be read backwards, for example, 1110 is It cannot be reversed because 0 cannot be used as a starting number.
One day, tragedy finally happened. A clerk accidentally hung up two of the price tags in the store. And the TVs of these two price tags have been sold!
Fortunately, the price difference is not large. One of the price tags lost more than 200, and the other price tag made more than 800. Combined, they made more money. 558 yuan.
Calculate based on this information: What should be the correct price for the losing price tag?
insert image description here

topic analysis
topic code



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, and if not, 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 code



Question 6: Reverse Polish Expressions

Topic description
Normal expressions are called infix expressions. The operator is in the middle, which is mainly for human reading, and it is not convenient for machines to solve.
For example: 3 + 5 * (2 + 6) - 1
Also, parentheses are often required to change the order of operations.
On the contrary, if the reverse Polish expression (prefix expression) is used, the above expression is expressed as:
- + 3 * 5 + 2 6 1
No parentheses are needed, and the machine can easily solve it recursively.
For simplicity, we assume:

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

The following program evaluates a reverse Polish representation string.
Its return value is a structure: where the first element represents the result of the evaluation, 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 code



Question 7: Wrong bills

Topic description
A secret-related unit has issued some kind of bills, and they will all be recovered at the end of the year.
Each ticket has a unique ID number. The ID numbers for all notes throughout the year are consecutive, but the starting numbers of the IDs are randomly selected.
Due to the negligence of the staff, an error occurred when entering the ID number, resulting in a broken ID for one ID and a duplicate ID for another ID.
Your task is to programmatically find out the ID of the break number and the ID of the double number.
It is assumed that break numbers cannot occur at the largest and smallest numbers.
The program is required to first input an integer N (N<100) to represent the number of data lines that follow.
Then read in N lines of data.
The length of each line of data varies, and is a number of (not more than 100) positive integers (not more than 100,000) separated by spaces.
Each integer represents an ID number.
The program is required to output 1 line, containing two integers mn, separated by spaces.
Among them, m represents the break ID, n represents the repeat ID

Example:
User input:
2
5 6 8 11 9
10 12 9

Then the program output:
7 9

Another example:
User Enter:
6
164 178 108 109 180 155 141 159 104 182 171 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 151 143 175 120 161 134 162 190
149 138 142 146 1993 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

Then the program output:
105 120

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

topic analysis
topic code



Question 8: The amount that cannot be bought

Topic Description
Xiao Ming opened a candy store. He is ingenious: the fruit candy is packaged into two types: a pack of 4 and a pack of 7. Candy cannot be sold unpacked.
When a child comes to buy candy, he uses these two packages to combine. Of course, some candies cannot be combined, such as buying 10 candies.
You can test it with a computer, in this case, the maximum quantity you can't buy 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 quantity of two packages is known.

Input:
Two positive integers, indicating the number of sugars in each package (no 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 lattice

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 figure to get two parts, each of which sums to 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, output the minimum number of cells contained in the area containing the upper left cell.
If it cannot be split, output 0

Program input and output format requirements:
the program first reads two integers mn, and divides them with spaces (m, n<10)
to indicate the width and height of the table.
Next are n lines, each line contains m positive integers, separated by spaces. Each integer is not greater than 10000
Program output: In all solutions, the minimum number of cells that the partition containing the upper left corner may contain.

Example:
User input:
3 3
10 1 52
20 30 1
1 2 3

Then the program output:
3

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

Then the program output:
10

(see p2.jpg)

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

insert image description here
insert image description here

topic analysis
topic code



Question 10: Minister's Travel Expenses

Title Description
A long time ago, the T Kingdom prospered unprecedentedly. 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 developed a set of excellent construction plans after thinking, so that any big city can be reached directly from the capital or indirectly through other big cities. At the same time, the plan to reach each big city from the capital is unique if it does not pass through the big cities repeatedly.
J is an important minister of country T. He patrols the major cities and observes the public sentiment. So, going from one city to another without stopping has become J's most common thing to do. He has a purse to store travel expenses between cities.
Smart J found that if he did not stop for repairs in a certain city, in the process of continuous travel, the toll he spent was related to the distance he had traveled. In (x is an integer), he spends as much as x+10. That is to say, it costs 11 to walk 1 km, and 23 to walk 2 km.
Minister J would like to know: What is the maximum travel expenses he may spend from a certain city to another city without rest in between?
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 from 1, and city No. 1 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 at most.

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

Sample output:
135

Example description:
Minister J costs 135 to travel from city 4 to city 5.

Consider supporting larger data sizes whenever possible based on resource constraints.

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

topic analysis
topic code



Guess you like

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