2016 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: The age of the netizen

Topic description A
new friend has met a netizen.
When asked about the age, his netizen said:
"My age is a two-digit number. I am 27 years older than my son.
If I swap the two digits of my age, it will be my son's age."
Please calculate: How many possible situations are there for the age of a netizen?
Reminder: 30 years old is one of the possibilities.
Please fill in the number of possible situations.
Topic analysis
topic codes



Question 2: Birthday candles

Description of the title
A certain person has held a birthday party every year since a certain year, and every time he blows out the same number of candles as his age.
Counting now, he blew out a total of 236 candles.
Excuse me, at what age did he start his birthday party?
Please fill in the age when he started the birthday party.
Topic analysis
topic codes



Question 3: Fill in the squares

Topic description
10 grids as follows
Insert picture description here

(If there is a problem with the display, you can also refer to [Figure 1.jpg])

Fill in the numbers from 0 to 9. Requirement: Two consecutive numbers cannot be adjacent.
(Left and right, up and down, and diagonally are all considered adjacent)

How many possible filling schemes are there?

Please fill in an integer representing the number of plans.
Topic analysis
topic codes



Fourth question: Quick sort

Topic description
Sorting is often used in various situations.
Quick sort is a very commonly used and efficient algorithm.
The idea is: first select a "ruler" and
use it to sift the entire queue
to ensure that the elements on its left are not larger than it, and the elements on its right are not smaller than it.
In this way, the sorting problem is divided into two sub-intervals.
Then sort the subintervals separately.

The following code is an implementation. Please analyze and fill in the missing codes in the underlined part.

#include <stdio.h>

void swap(int a[], int i, int j)
{
    
    
	int t = a[i];
	a[i] = a[j];
	a[j] = t;
}

int partition(int a[], int p, int r)
{
    
    
    int i = p;
    int j = r + 1;
    int x = a[p];
    while(1){
    
    
        while(i<r && a[++i]<x);
        while(a[--j]>x);
        if(i>=j) break;
        swap(a,i,j);
    }
	______________________;
    return j;
}

void quicksort(int a[], int p, int r)
{
    
    
    if(p<r){
    
    
        int q = partition(a,p,r);
        quicksort(a,p,q-1);
        quicksort(a,q+1,r);
    }
}
    
int main()
{
    
    
	int i;
	int a[] = {
    
    5,13,6,24,2,8,19,27,6,12,1,17};
	int N = 12;
	
	quicksort(a, 0, N-1);
	
	for(i=0; i<N; i++) printf("%d ", a[i]);
	printf("\n");
	
	return 0;
}

Topic analysis
topic codes



Question 5: Eliminate the last one

Title description
The following code changes the rightmost consecutive 1s in the binary representation of an integer to 0.
If the last digit is 0, the original number remains unchanged.

If you use the test data in the code, it should output:
00000000000000000000000001100111 00000000000000000000000001100000
00000000000000000000000000001100 00000000000000000000000000001100

Please read the program carefully and fill in the missing codes in the underlined part.

#include <stdio.h>

void f(int x)
{
    
    
	int i;
	for(i=0; i<32; i++) printf("%d", (x>>(31-i))&1);
	printf("   ");
	
	x = _______________________;
	
	for(i=0; i<32; i++) printf("%d", (x>>(31-i))&1);
	printf("\n");	
}

int main()
{
    
    
	f(103);
	f(12);
	return 0;
}

Topic analysis
topic codes



Sixth question: Winter homework

Topic description
Now the math problems in elementary school are not so fun.
Take a look at this winter homework:

□ + □ = □
□ - □ = □
□ × □ = □
□ ÷ □ = □

(If it is not displayed, please refer to [Figure 1.jpg])

Each square represents a certain number from 1 to 13, but cannot be repeated.
For example:
6 + 7 = 13
9-8 = 1
3 * 4 = 12
10/2 = 5

And:
7 + 6 = 13
9-8 = 1
3 * 4 = 12
10/2 = 5

Even two solutions. (Addition and multiplication are different schemes after the commutative law)

How many solutions have you found?

Please fill in an integer representing the number of plans.
Insert picture description here

Topic analysis
topic codes



Question 7: Cut stamps

Title description
As shown in [Picture 1.jpg], there are 12 stamps with 12 zodiac signs connected together.
Now you have to cut out 5 sheets from it, the requirement must be connected.
(Just connecting one corner does not count as connected) For
example, in [Picture 2.jpg], [Picture 3.jpg], the part shown in pink is a qualified cut.

Please calculate how many different clipping methods there are.

Please fill in an integer representing the number of plans.

Insert picture description here

Insert picture description here
Insert picture description here

Topic analysis
topic codes



Question 8: Four square sum

Title Description The
Four Squares Theorem, also known as Lagrange's Theorem:
Every positive integer can be expressed as the sum of the squares of at most 4 positive integers.
If you include 0, it can be expressed as the sum of the squares of 4 numbers.

For example:
5 = 0^2 + 0^2 + 1^2 + 2^2
7 = 1^2 + 1^2 + 1^2 + 2^2
(^ sign means power)

For a given positive integer, there may be multiple representations of the sum of squares.
You are required to sort the 4 numbers:
0 <= a <= b <= c <= d
and arrange all possible representations in ascending order by a, b, c, d as the joint primary key, and finally output the first representation

The program input is a positive integer N (N<5000000)
. 4 non-negative integers are required to be output, sorted from small to large, separated by spaces

For example, input:
5
, the program should output:
0 0 1 2

For another example, input:
12
, the program should output:
0 2 2 2

For another example, input:
773535
, the program should output:
1 1 267 838

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



Question 9: Loss of password

The title describes
the archaeologists on Planet X discovered a number of ancient codes.
These codes are sequences made up of the seeds of the four plants A, B, C, and D.
Careful analysis revealed that these password strings should be symmetrical (that is, what we call mirror strings).
Due to the age, many of the seeds have fallen off and may lose their mirror image characteristics.

Your task is:
given a password string you see now, calculate how many seeds it has to shed from its original state before it can become its current state.

Enter a line to indicate that the password string you see now (the length is not greater than 1000)
requires a positive integer to indicate at least how many seeds are dropped.

For example, input:
ABCBA
, the program should output:
0

For another example, input:
ABDCDCBABC
, the program should output:
3

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



Question 10: Maximum ratio

The title describes
a certain Grand Prix on Planet X with an M-level award. The bonus for each level is a positive integer.
Also, the ratio between two adjacent levels is a fixed value.
That is to say: the bonus numbers of all levels constitute a geometric series. For example:
16,24,36,54
whose equal ratio is 3/2

Now, we randomly surveyed the prize numbers of some winners.
Please calculate the largest possible ratio based on this.

Input format: The
first line is a number N (0<N<100), which means that the next line contains N positive integers. The
second line contains N positive integers Xi (Xi<1 000 000 000 000), separated by spaces. Each whole number represents the amount of bonus of someone surveyed

Required output:
A score in the form of A/B, requiring A and B to be relatively prime. Represents the largest possible scale factor

The test data ensures that the input format is correct and the maximum ratio exists.

For example, enter:
3
1250 200 32

The program should output:
25/4

For another example, enter:
4
3125 32 32 200

The program should output:
5/2

For another example, enter:
3
549755813888 524288 2

The program should output:
4/1

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



Guess you like

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