2015 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


The first problem: the integer solution of the equation

Title description
Equation: a^2 + b^2 + c^2 = 1000
(or refer to [Figure 1.jpg])
Does this equation have an integer solution? There are: a,b,c=6,8,30 is a set of solutions.
Can you calculate another suitable solution?

Please fill in the smallest number in the solution.
Insert picture description here

Topic analysis
topic codes



Question 2: Galaxy Bomb

Title description
There are many X-star artificial "bombs" floating in the vast space of the X galaxy, which are used as road signs in the universe.
Each bomb can be set to explode in days.
For example, if the Alpha Bomb is placed on January 1, 2015 and the time is 15 days, it will explode on January 16, 2015.
There is a beta bomb, which was placed on November 9, 2014, with a timing of 1000 days. Please calculate the exact date when it exploded.

Please fill in the date, the format is yyyy-mm-dd, which is a 4-digit year, 2-digit month and 2-digit date. For example: 2015-02-19
please write in strict accordance with the format. No other words or symbols can appear.
Topic analysis
topic codes



Question 3: Wonderful numbers

Title description
Xiao Ming found a strange number. Its square and cube use each of the 10 numbers from 0 to 9 and only use it once.
Can you guess what this number is?
Topic analysis
topic codes



Fourth question: output in the grid

Title description
StringInGrid function will print the specified string in a grid of specified size.
The string is required to be centered in both the horizontal and vertical directions.
If the string is too long, it is truncated.
If it can't be exactly centered, you can move it slightly to the left or up.
The following program implements this logic, please fill in the missing code in the underlined part.

#include <stdio.h>
#include <string.h>

void StringInGrid(int width, int height, const char* s)
{
    
    
	int i,k;
	char buf[1000];
	strcpy(buf, s);
	if(strlen(s)>width-2) buf[width-2]=0;
	
	printf("+");
	for(i=0;i<width-2;i++) printf("-");
	printf("+\n");
	
	for(k=1; k<(height-1)/2;k++){
    
    
		printf("|");
		for(i=0;i<width-2;i++) printf(" ");
		printf("|\n");
	}
	
	printf("|");
	
	printf("%*s%s%*s",_____________________________________________);  //填空
	          
	printf("|\n");
	
	for(k=(height-1)/2+1; k<height-1; k++){
    
    
		printf("|");
		for(i=0;i<width-2;i++) printf(" ");
		printf("|\n");
	}	
	
	printf("+");
	for(i=0;i<width-2;i++) printf("-");
	printf("+\n");	
}

int main()
{
    
    
	StringInGrid(20,6,"abcd1234");
	return 0;
}

For the data in the title, it should output:
±-----------------+
| |
| abcd1234 |
| |
| |
±------------- ----+
Insert picture description here

(If there is an alignment problem, please refer to [Figure 1.jpg]) Question code for
question analysis



Question 5: Nine group scores

Title description
1,2,3...9 These nine numbers form a score, and its value is exactly 1/3. How to group it?
The following program implements this function, please fill in the missing code in the underlined part.

#include <stdio.h>

void test(int x[])
{
    
    
	int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
	int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];
	
	if(a*3==b) printf("%d / %d\n", a, b);
}

void f(int x[], int k)
{
    
    
	int i,t;
	if(k>=9){
    
    
		test(x);
		return;
	}
	
	for(i=k; i<9; i++){
    
    
		{
    
    t=x[k]; x[k]=x[i]; x[i]=t;}
		f(x,k+1);
		_____________________________________________ // 填空处
	}
}
	
int main()
{
    
    
	int x[] = {
    
    1,2,3,4,5,6,7,8,9};
	f(x,0);	
	return 0;
}

Topic analysis
topic codes



Question 6: Number of card types

Title description
Xiao Ming was hijacked to Casino X and forced to play cards with 3 other people.
A deck of playing cards (without the big and small trump cards, a total of 52), evenly distributed to 4 people, each with 13 cards.
At this time, a question suddenly appeared in Xiao Ming's mind:
If you don't consider suits, only points, and not the order of the cards you get, how many kinds of initial card combinations can you get in your hand?
Topic analysis
topic codes



Question 7: Bracelet style

Title description
Xiao Ming has 3 red corals, 4 white corals, and 5 yellow agates.
He wanted to use them in a circle as a bracelet to give to his girlfriend.
Now Xiao Ming wants to know: If you consider that the bracelet can be turned or flipped at will, how many different combinations can there be?
Topic analysis
topic codes



Question 8: Drink redemption

Topic description
Leyangyang Beverage Factory is holding a promotional activity. Leyangyang C-type beverage, with 3 caps, you can change to another C-type beverage, and it can be recycled forever (but temporary loan or credit is not allowed).

Please calculate, if Xiao Ming does not waste bottle caps and participates in activities as much as possible, then, for the n bottles of beverages he initially bought, how many bottles of beverages he can drink in the end.

Input: an integer n, indicating the number of drinks to purchase (0<n<10000)
Output: an integer indicating the number of drinks actually obtained

For example:
User input:
100 The
program should output:
149

User input:
101 The
program should output:
151

Resource agreement:
peak memory consumption <256M
CPU consumption <1000ms
question analysis
question code



Question 9: Base dice

Title description The
gambling atm became obsessed with dice in his later years, that is, he puts the dice on top of the other, not crooked, and has to be square cylinders.
After long-term observation, ATM has discovered the mystery of stable dice: the faces of some numbers will repel each other!
Let's first standardize the dice: the opposite of 1 is 4, the opposite of 2 is 5, and the opposite of 3 is 6.
Assuming that there are m groups of mutual exclusion, the faces of the two numbers in each group are close to each other, and the dice cannot stand up stably.
Atm wants to calculate how many different possible ways to base the dice.
The two ways to base the dice are the same, if and only if the directions of the corresponding numbers of the dice of the corresponding height in the two ways are the same.
Since there may be too many solutions, please output the result modulo 10^9 + 7.

Don’t underestimate the number of dice in ATM~

The
two integers nm
n in the first line of the "input format" represent the number of dice. The
next m lines have two integers ab in each line, indicating that the numbers a and b cannot be close together.

"Output Format" has
a number on a line, which means the answer modulo 10^9 + 7.

"Sample Input"
2 1
1 2

"Sample Output"
544

"Data range"
of 30% of the data: n <= 5
data for 60%: n <= 100
to 100% of the data: 0 <n <= 10 ^ 9, m <= 36
Title Analysis
entitled Code



Question 10: Post-disaster reconstruction

The title describes that
there are N (<=50000) residential areas in Pear City, and M (<=200000) two-way roads are connected between the residential areas. Both of these settlements can be reached by two-way roads. This situation continued until recently, when a severe earthquake destroyed all M roads.
After the earthquake, Pear intends to repair some of these roads. Repairing the i-th road will take Pi's time. However, Pear does not intend to connect all the points, but chooses some specially labeled points to connect them.
Pear has Q (<=50000) queries. Each time he asks, he will select all the points whose numbers are between [l,r] and whose numbers are mod K = C, and repair some paths to make them connected. Since all road repairs can be started at the same time, the time to complete the repair depends on the road that takes the longest time, that is, the maximum value of Pi among the roads involved.

Can you help Pear calculate the minimum time required for each inquiry? The inquiry here is independent, that is, the repair plan in the previous inquiry was not put into action.

[Input format] The
three positive integers N, M, and Q in the first line have meanings as described in the title.
In the next M lines, each line has three positive integers Xi, Yi, Pi, indicating a two-way road connecting Xi and Yi, and it takes time for Pi to repair. There may be self-loops, and there may be heavy edges. 1<=Pi<=1000000.

In the next line Q, there are four positive integers Li, Ri, Ki, Ci in each line, indicating that the point in question this time is all points in the interval [Li, Ri] with numbers Mod Ki=Ci. Ensure that there are at least two points involved in the inquiry.

[Output format]
output Q lines, each line a positive integer represents the answer to the corresponding inquiry.

[Sample input]
7 10 4
1 3 10
2 6 9
4 1 5
3 7 4
3 6 9
1 5 8
2 7 4
3 2 10
1 7 6
7 6 9
1 7 1 0
1 7 3 1
2 5 1 0
3 7 2 1

[Sample output]
9
6
8
8

[Data range]
For 20% data, N, M, Q<=30
For 40% data, N, M, Q<=2000
For 100% data, N<=50000, M<=2*10^ 5,Q<=50000. Pi<=10^6. Li, Ri, Ki are all in the range of [1,N], and Ci is in the range of [0, corresponding to Ki).
Topic analysis
topic codes



Guess you like

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