2018 9th C/C++ Group B Blue Bridge Cup Provincial Tournament 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 first few days

The title describes
January 1, 2000, which is the first day of that year.
So, on May 4th, 2000, which day was that year?
Note: What needs to be submitted is an integer, do not fill in any extra content.

Analysis of the question
, just do it by hand, the simplest question code in the previous blue bridge cup calculation dates

#include<iostream>

using namespace std;
int main()
{
    
    
	//首先2000年是闰年 2月29天 
	int ans = 31+29+31+30+4;
	cout << ans <<endl;
	return 0; 
} 

Question answer

125

Question 2: Clear code

Title description
The glyphs of Chinese characters exist in the font library. Even today, the 16-dot font library is still widely used.
The 16-dot font library regards each Chinese character as 16x16 pixel information. And record this information in bytes.

One byte can store 8 bits of information, and 32 bytes can store the shape of a Chinese character.
Convert each byte to binary representation, 1 means ink, 0 means background color. Each line has 2 bytes, a
total of 16 lines, the layout is:

1st byte, 2nd byte
3rd byte, 4th byte
...
31st byte, 32nd byte

This question is to give you a piece of information composed of multiple Chinese characters. Each Chinese character is represented by 32 bytes. The value of the byte as a signed integer is given here.

The requirements of the subject are hidden in this information. Your task is to restore the glyphs of these Chinese characters, see the requirements of the questions from them, and fill in the answers as required.

This piece of information is (a total of 10 Chinese characters):
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0
16 64 16 64 34 68 127 126 66 -124 67 4 66 4 66 -124 126 100 66 36 66 4 66 4 66 4 126 4 66 40 0 ​​16
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0
0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4
4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64
16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128
0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0
2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0
1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0
0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0

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

Problem analysis
Here you need to use the bitset library in the C++ library to convert the shaping into byte rows, and then output the
problem code

#include<iostream>
#include<bitset>
using namespace std;

int main()
{
    
    
	int a,b;
	for(int i = 0; i < 10; i++)
	{
    
    
		for(int j = 0; j < 16; j++)
		{
    
    
			cin >> a >> b;
			bitset<8> x(a),y(b);
			cout << x.to_string()<<y.to_string()<<endl;
		}
		cout << endl<<endl;
	}
	long long int ans;
	ans = pow(9,9);
	cout<<ans<<endl; 
} 

Question answer

//九的九次方是多少?
387420489

Question 3: End of product with zero

Title description The
following 10 rows of data, each row has 10 integers, how many zeros are there at the end of their product?

5650 4542 3554 473 946 4114 3871 9073 90 4329
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899
1486 5722 3135 1170 4014 5510 5120 729 2880 9019
2049 698 4582 4346 4427 646 9742 7340 1230 7683
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649
6701 6645 1671 5978 2704 9926 295 3125 3878 6785
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074
689 5510 8243 6114 337 4096 8199 7313 3685 211

Note: What needs to be submitted is an integer, which represents the number of zeros at the end. Don't fill in any redundant content.
Title Analysis
herein may be multiplied by a 10 obtained from 2 and 5, so long as the number is calculated the number of each of the 2 and 5 on the line, the number of the last constitutes the minimum number of zero
topic codes

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    
    
	int num5 = 0,num2 = 0,x;
	for(int i = 0; i < 100; i++)
	{
    
    
		cin >> x;
		if(x==0)
		{
    
    
			cout << "0" <<endl;
			return 0;
		}
		while(1)
		{
    
    
			if(x%5==0)
			{
    
    
				num5++;
				x/=5;
			}
			else if(x%2==0)
			{
    
    
				num2++;
				x/=2;
			}
			else
			{
    
    
				break;
			}
				
		}
	}
	cout << min(num5,num2) << endl;
	return 0;
	
}

Question answer

31

Question 4: Number of tests

The title describes
that the residents of Planet X have a bad temper, but fortunately, the only unusual behavior when they are angry is to drop their mobile phones.
Major manufacturers have also launched a variety of drop-resistant mobile phones. The Quality Supervision Bureau of Planet X stipulates that mobile phones must undergo a drop resistance test, and a drop resistance index has been assessed before they are allowed to be marketed.

Planet X has many towering towers that can be used for fall resistance tests. The height of each floor of the tower is the same. What is slightly different from the earth is that their first floor is not the ground, but is equivalent to our second floor.

If the phone is thrown from the 7th layer and it is not broken, but the 8th layer is broken, the mobile phone withstand index=7.
In particular, if the mobile phone breaks when dropped from the first layer, the drop resistance index=0.
If the nth floor of the highest floor of the tower is not broken, then the drop resistance index = n

In order to reduce the number of tests, sample 3 mobile phones from each manufacturer to participate in the test.

The tower height of a certain test is 1000 floors. If we always adopt the best strategy, how many times do we need to test at most to determine the phone's drop resistance index under the worst luck?

Please fill in this maximum number of tests.

Note: What needs to be filled in is an integer, do not fill in any redundant content.

Problem analysis
Use the DP algorithm to partition the number of layers to construct a local optimal solution. For details, please refer to the analysis
topic code

#include<stdio.h> 

#define Max(a,b) (a>b?a:b)

#define Min(a,b) (a<b?a:b)

int dp[1002][5];

int main(){
    
    

	for(int i =1; i <=1000; i++){
    
    //初始化边界

		dp[i][1] = i;

	}

	for(int cnt =2; cnt <=3; cnt++){
    
    

		for(int ind =1; ind <=1000; ind++){
    
    

			dp[ind][cnt] =dp[ind-1][cnt] +1;

			for(int k =2; k <= ind; k++){
    
    

				dp[ind][cnt] =Min(dp[ind][cnt],1+Max(dp[k-1][cnt-1],dp[ind-k][cnt]));

			}

		}

	}

	printf("%d\n",dp[1000][3]);

	return 0;

}

Question answer

19

Question 5: Quick Sort

Title description The
following code can find the k-th smallest element from the array a[].
It uses a divide-and-conquer algorithm similar to quicksort, and the expected time complexity is O(N).
Please read and analyze the source code carefully, and fill in the missing content in the underlined part.

#include <stdio.h>

int quick_select(int a[], int l, int r, int k) {
    
    
	int p = rand() % (r - l + 1) + l;
	int x = a[p];
	{
    
    int t = a[p]; a[p] = a[r]; a[r] = t;}
	int i = l, j = r;
	while(i < j) {
    
    
		while(i < j && a[i] < x) i++;
		if(i < j) {
    
    
			a[j] = a[i];
			j--;
		}
		while(i < j && a[j] > x) j--;
		if(i < j) {
    
    
			a[i] = a[j];
			i++;
		}
	}
	a[i] = x;
	p = i;
	if(i - l + 1 == k) return a[i];
	if(i - l + 1 < k) return quick_select( _____________________________ ); //填空
	else return quick_select(a, l, i - 1, k);
}
	
int main()
{
    
    
	int a[] = {
    
    1, 4, 2, 8, 5, 7, 23, 58, 16, 27, 55, 13, 26, 24, 12};
	printf("%d\n", quick_select(a, 0, 14, 5));
	return 0;
}


Quick sorting of topic analysis . As a classic algorithm, you must learn it. If you don’t learn it, ask the data structure teacher. Here is a brief introduction, which is to choose a number each time, and then compare the number on the left to make the number on the left less than the selected number. , The number on the right is greater than the selected number. Then quickly sort the question codes on the left and right sides


Question answer

 a, i+1, r, k-(i-l+1)

Question 6: Incremental triples

Title description
Given three integer arrays
A = [A1, A2,… AN],
B = [B1, B2,… BN],
C = [C1, C2,… CN],
please count how many triples there are (i, j, k) satisfies:

  1. 1 <= i, j, k <= N
  2. Ai < Bj < Ck

[Input format] The
first line contains an integer N.
The second line contains N integers A1, A2,… AN.
The third line contains N integers B1, B2,… BN.
The fourth line contains N integers C1, C2,… CN.

For 30% data, 1 <= N <= 100
For 60% data, 1 <= N <= 1000
For 100% data, 1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000

[Output format]
An integer represents the answer

【Sample input】
3
1 1 1
2 2 2
3 3 3

【Sample output】
27

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 7: Spiral Polyline

Title description
The spiral polyline shown in Figure p1.png passes through all the whole points on the plane exactly once.
For the whole point (X, Y), we define its distance to the origin dis(X, Y) to be the length of the spiral polyline segment from the origin to (X, Y).
For example, dis(0, 1)=3, dis(-2, -1)=9
gives the coordinates of the whole point (X, Y), can you calculate dis(X, Y)?
Insert picture description here

[Input format]
X and Y

For 40% data, -1000 <= X, Y <= 1000
For 70% data, -100,000 <= X, Y <= 100000
For 100% data, -1000000000 <= X, Y <= 1000000000

[Output format]
output dis(X, Y)

【Sample input】
0 1

【Sample output】
3

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 8: Log Statistics

Title description
Xiao Ming maintains a programmers forum. Now he has collected a "like" log with N lines in total. The format of each line is:

ts id

Indicates that the post numbered id at ts time received a "like".
Now Xiao Ming wants to count which posts were once "hot posts". If a post has received no less than K likes in any time period of length D, Xiao Ming thinks that the post was once a "hot post".
Specifically, if there is a certain moment T that satisfies that the post receives no less than K likes during the period of [T, T+D) (note that the left-closed and right-open interval), the post was once "hot Post".
Given a log, please help Xiao Ming count all the post numbers that were once "hot posts".

[Input format] The
first line contains three integers N, D and K.
The following N lines have one log per line, containing two integers ts and id.
For 50% data, 1 <= K <= N <= 1000
For 100% data, 1 <= K <= N <= 100000 0 <= ts <= 100000 0 <= id <= 100000
【Output format】
The hot post id will be output in ascending order. One line per id.
[Sample input]
7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3
[Sample output]
1
3
Resource convention:
Peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 9: Global Warming

Title description
You have a picture of a certain sea area with NxN pixels, "." means ocean, "#" means land, as shown below:


.##…
.##…
…##.
…####.
…###.

Among them, a piece of land connected in four directions "up, down, left, and right" forms an island. For example, there are 2 islands in the picture above.

As global warming has caused the sea to rise, scientists predict that in the next few decades, a pixel area on the edge of the island will be submerged by sea water. Specifically, if a land pixel is adjacent to the ocean (there is an ocean among the four adjacent pixels up, down, left, and right), it will be submerged.

For example, the sea area in the above picture will become as follows in the future:

.......
.......
.......
.......
....#..
.......
.......

Please calculate: According to the prediction of scientists, how many islands in the photo will be completely submerged.

[Input format] The
first line contains an integer N. (1 <= N <= 1000) The
following N rows and N columns represent a sea area photo.

The picture guarantees that the pixels in the first row, the first column, the Nth row, and the Nth column are all oceans.

[Output format]
An integer represents the answer.

【Input sample】
7

.......
.##....
.##....
....##.
..####.
...###.
.......  

[Sample output]
1

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 10: Maximum product

Title description
Given N integers A1, A2,… AN. Please select K numbers from them to maximize their product.
Please find the largest product, because the product may exceed the integer range, you only need to output the remainder of the product divided by 1000000009.
Note that if X<0, we define the remainder of X divided by 1000000009 to be the remainder of negative (-X) divided by 1000000009.
That is: 0-((0-x)% 1000000009)

[Input format] The
first line contains two integers N and K.
Each of the following N lines has an integer Ai.

For 40% data, 1 <= K <= N <= 100
For 60% data, 1 <= K <= 1000
For 100% data, 1 <= K <= N <= 100000 -100000 <= Ai <= 100000
[Output format]
An integer, representing the answer.
[Input sample]
5 3
-100000
-10000
2
100000
10000
[Output sample]
999100009
Another example:
[Input sample]
5 3
-100000
-100000
-2
-100000
-100000
[Output sample]
-999999829
Resource agreement:
Peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes


Guess you like

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