In April 2022, the 13th Lanqiao Cup Provincial Competition Group C C Language/C++ Real Questions and Answers

After participating in so many algorithmic competitions and certifications, I have concluded a very important ability,
project evaluation ability: can I judge more accurately whether I can complete a certain question at my current level, and how much it will cost to complete this question? Time
Especially in the high-pressure environment of competitions, I always want to seize every minute and every second and "just do it" when I see the questions.
Facts have proved that this is not a good decision. Before your level has not reached the level of being able to quickly AC all the questions, you still have to distinguish the importance of each question. If it is too big to measure, you must give up in time or plan to only take part of the points. After all, everyone has different proficiency in different question types.

By the way, the Blue Bridge Cup is not a test of the understanding of the algorithm at all, but a test of the coding proficiency of the contestants. Four hours of ten programming questions who can do this??? Submitted and no feedback on the results, there are a few questions The scale is still quite large, and you have to evaluate the time complexity of the program by yourself. For a coder like me who doesn't type code, "You're welcome, I won't participate next time." Look at
ACM and CCSP next door, you can bring books You can even bring a USB flash drive. From this point, it can be seen that the Lanqiao Cup exam is all about basic programming skills.

If you are lucky enough to help you, don’t forget to praise Ha San Ke Oil~

topic

The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C
The 13th Blue Bridge Cup Software Competition Provincial Competition
C/C++ University Group C
[Notes to Candidates]
After the exam starts, the contestants first download the questions, and Use the decompression password published on the test site to decompress the test
questions.
The exam time is 4 hours. During the test, contestants can browse the answers they have submitted, and the browsed
answers are allowed to be copied. After the time expires, no further submissions or browsing of answers will be possible.
For the same question, contestants can submit answers multiple times, and the last submitted answer shall prevail.
Contestants must submit their answers through a browser. Competitors' answers in other positions or
submitted by other means are invalid.
The test questions include "result filling in the blanks" and "programming" two types of questions.
Result fill-in-the-blank question: contestants are required to directly fill in the result according to the description of the question. The solution method is not limited.
No source code is required . Just submit the answers to fill in the blanks directly through the webpage, and do not write redundant content.
Program design question: The program designed by the contestant is required to give the correct output result for the given input.
Candidates have a chance to score points only if their programs can produce correct results.
Note: The input data used for marking may be different from the example data given in the exam paper.
The contestant's program must be universal and cannot only be valid for the data given in the test paper.
For programming questions, the answers given by contestants are required to fully comply with the GNU C/C++ standard, and
APIs such as graphics, Win32API, interrupt calls, hardware operations, or operating system-related APIs cannot be used.
STL class libraries are allowed in the code.
Note: The main function must return 0 at the end.
Note: All dependent functions must be clearly #included in the source file, and
common header files cannot be omitted through project settings.
All source code must be in the same file. After the debugging is passed, copy and submit.
When submitting, be careful to select the desired compiler type.
The 13th Blue Bridge Cup Software Competition Provincial Competition 1
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Test question A: Arranging letters

Total score for this question: 5 points
[Problem description]
Xiaolan wants to arrange the letters in a string according to their order in the alphabet.
For example, LANQIAO ranks as AAILNOQ.
Another example, GOODGOODSTUDYDAYDAYUP is arranged as AADDDDDGGOOOOPSTUUYYY
.
For the following strings, what is the string after permutation?
WHERETHEREISAWILLTHEREISAWAY
[Answer submission]
This is a question to fill in the blanks with the result, you only need to calculate the result and submit it. The result of this question is a
string composed of uppercase letters. Only fill in this string when submitting the answer, and you
will not get points if you fill in redundant content.
Question A: Arranging Letters 2
The 13th Blue Bridge Cup Competition Software Competition Provincial Competition C/C++ University Group C

Question B: Special Time

Total score for this question: 5 points
[Problem description]
22:20 on February 22, 2022 is a very meaningful time. The year is 2022, which consists of three 2s and one 0. If the month and day are written as 4 digits, It is 0222, which is also composed of 3 2s and 1 0.
If the hour and minute in the time are written as 4 digits, it is still composed of 3 2s and 1 0.
Xiaolan is very interested in such time, and he also found other similar examples, such as 01:11 on October 11, 111,
22:02 on February 22, 2202, and so on.
Excuse me, how many times in total are the year written in 4 digits, the month and day written in 4 digits, and the time written in
4 digits, which are composed of 3 numbers of one kind and 1 number of another kind. Note that 11:11, November 11, 1111
does not count because it does not have two numbers in it.
[Answer Submission]
This is a question to fill in the blanks, you only need to calculate the result and submit it. The result of this question is an
integer. When submitting the answer, only fill in this integer. If you fill in the redundant content, you will not get points.
Question B: Special Time 3
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Question C: Paper Size

Time limit: 1.0s Memory limit: 256.0MB Total score of this question: 10 points
[Problem description]
The size of A0 paper is defined in the ISO international standard as 1189mm × 841mm.
After folding the A0 paper in half along the long side, it becomes an A1 paper with a size of 841mm × 594mm, the length is directly removed during the process of folding in half
(there may be loss during actual cutting). Fold A1 paper in half along the long side to A2 paper, and so on.
Enter the name of the paper, please output the size of the paper.
【Input format】
Enter a line containing a character string indicating the name of the paper, which must be one
of A0, A1, A2, A3, A4, A5, A6, A7, A8, A9.
[Output format]
Output two lines, each line contains an integer, which in turn represents the length of the long side and short side.
[Sample input 1]
A0
[Sample output 1]
1189
841
[Sample input 2]
A1
[Sample output 2]
841
594
Question C: Paper size 4
The 13th Blue Bridge Cup Competition Software Competition Provincial C/ C++ University C Group

Question D: Summation

Time limit: 1.0s Memory limit: 256.0MB Total score of this question: 10 points
[Problem description]
Given n integers a1, a2, · · ·, an , find the sum of multiplying and adding them two by two, that is,
S = a1 · a2 + a1 · a3 + · · · + a1 · an + a2 · a3 + · · · + ann 2 · ann 1 + ann 2 · an + ann 1 · an. 【Input format】The first input
line
contains an integer n.
The second line contains n integers a1, a2, · · · an.
[Output format]
Output an integer S, representing the sum sought. Please use the appropriate data type for operations.
[Sample input]
4
1 3 6 9
[Sample output]
117
[Evaluation case scale and agreement]
For 30% of the data, 1 ≤ n ≤ 1000, 1 ≤ ai ≤ 100.
For all evaluation cases, 1 ≤ n ≤ 200000, 1 ≤ ai ≤ 1000.
Question D: Summation 5
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Question E: Numeric Sorting

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points
[Problem description]
Xiaolan is very interested in the sum of digits of a number, and today he wants to sort the numbers according to the sum of digits. When
the sums of the digits of two numbers are different, the digits with the smaller digits are arranged first; when the sums of the digits are equal, the digits with the
smaller digits are arranged first.
For example, 2022 comes before 409 because the sum of 2022's digits is 6, which is less than the sum of 409's digits,
which is 13.
As another example, 6 comes before 2022 because the sum of their digits is the same, and 6 is less than 2022. Given positive integers n, m, when sorting 1 to n by this method, what is the
mth element ? 【Input format】The first line of input contains a positive integer n. The second line contains a positive integer m. 【Output format】Output a line containing an integer, representing the answer. [Sample Input] 13 5 [Sample Output] 3 Question E: Digital Sorting 6 The 13th Blue Bridge Cup Competition Software Competition Provincial C/C++ University Group C [Sample Description] The order of 1 to 13 is: 1 , 10, 2, 11, 3, 12, 4, 13, 5, 6, 7, 8, 9. The fifth number is 3. [Evaluation case scale and agreement] For 30% of the evaluation cases, 1 ≤ m ≤ n ≤ 300.

















For 50% of the evaluation cases, 1 ≤ m ≤ n ≤ 1000.
1 ≤ m ≤ n ≤ 106 for all evaluation cases.
Question E: Digital Sorting 7
The 13th Blue Bridge Cup Competition Software Competition Provincial Competition C/C++ University Group C

Question F: XOR

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points
[Problem description]
Given a sequence A1, A2, · · ·, An of length n and a non-negative integer x, given m
queries , each time it is asked whether two numbers can be selected from a certain interval [l,r] so that their XOR is equal to x.
[Input format]
The first line of input contains three integers n, m, x.
The second line contains n integers A1, A2, · · ·, An .
Next m lines, each line contains two integers li, ri representing the query interval [li, ri].
[Output format]
For each query, if the XOR of two numbers in the interval is x, then output yes, otherwise output
no.
[Sample input]
4 4 1
1 2 3 4
1 4
1 2
2 3
3 3
[Sample output]
yes
no
yes
no
Question F: XOR 8
The 13th Blue Bridge Cup Software Competition Provincial Competition C /C++ University C Group
[Example Explanation]
Apparently only the XOR of 2 and 3 is 1 in the entire array.
[Evaluation use case scale and agreement]
For 20% of the evaluation use cases, 1 ≤ n, m ≤ 100;
For 40% of the evaluation cases, 1 ≤ n, m ≤ 1000;
for all evaluation cases, 1 ≤ n, m ≤ 100000, 0 ≤ x < 2
20 , 1 ≤ li ≤ ri ≤ n , 0 ≤ Ai < 2
20.
Question F: XOR 9
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Test Question G: Elimination Game

Time limit: 1.0s Memory limit: 256.0MB Total score of this question: 20 points
[Problem description]
In a string S, if S i = S ii 1 and S i , S i+1 , then call S i and S i +1 for marginal
characters. If S i , S ii 1 and S i = S i+1, then S ii 1 and S i are also called edge characters. All other characters
are not border characters.
For a given string S, one operation can delete all marginal characters in the string at one time
(new marginal characters may be generated after the operation).
Please tell me what kind of string S becomes after 2
64 operations. If the result is empty,
output EMPTY.
【Input format】
Enter a line containing a string S.
[Output format]
Output a line containing a string representing the answer, and output EMPTY if the result is empty.
[Sample input 1]
edda
[Sample output 1]
EMPTY
[Sample input 2]
sdfhhhhcvhhxcxnnnnshh
[Sample output 2] s
Exam question G: Elimination game 10
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C
[Evaluation Case Scale and Agreement]
For 25% of the evaluation cases, |S| ≤ 103, where |S| represents the length of S;
For 50% of the evaluation cases, |S| ≤ 104;
for 75% of the evaluation cases, |S| ≤ 105;
for all evaluation cases, |S| ≤ 106, only lowercase letters in S.
Test Question G: Elimination Game 11
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Question H: Reordering

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 20 points
[Problem description]
Given an array A and some queries Li, Ri, find the sum of elements Li to Ri in the array.
Xiaolan thinks this question is boring, so he wants to rearrange the array so that the final sum
of each query result is as large as possible. Xiaolan wants to know how much the sum of all query results can
increase compared with the original array?
[Input format]
Input the first line contains an integer n.
The second line contains n integers A1, A2, · · ·, An, separated by a space between two adjacent integers.
The third line contains an integer m representing the number of queries.
Next m lines, each line contains two integers Li, Ri,
separated by a space between two adjacent integers.
[Output format]
Output a line containing an integer to represent the answer.
[Sample Input]
5
1 2 3 4 5
2
1 3
2 5
[Sample Output]
4
Question H: Reorder 12
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C
[Sample Description ]
The original sum is 6 + 14 = 20, rearranged as (1, 4, 5, 2, 3) and the sum is 10 + 14 = 24, with 4 added
.
[Evaluation use case scale and agreement]
n, m ≤ 50 for 30% of evaluation cases; n,
m ≤ 500 for 50% of evaluation cases; n, m ≤ 5000
for 70% of evaluation cases;
1 ≤ n, m ≤ for all evaluation cases 105, 1 ≤ Ai ≤ 106, 1 ≤ Li ≤ Ri ≤ 106.
Question H: Reordering 13
The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C

Question I: Skill Upgrading

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 25 points
[Problem description]
Xiaolan is playing an RPG game recently. His character has a total of N skills that can increase attack power
. Among them, the first upgrade of the i-th skill can increase the attack power of Ai points, and the points increased by each subsequent upgrade
will reduce Bi. After ⌈ Ai Bi⌉ (rounded up) times, upgrading the skill will not change the attack power.
Now Xiaolan can upgrade skills M times in total, and he can choose the skills and times to upgrade arbitrarily. Please
calculate how much attack power Xiaolan can increase at most?
【Input format】
The first line of input contains two integers N and M.
Each of the following N lines contains two integers Ai and Bi.
[Output format]
Output a line containing an integer to represent the answer.
[Sample input]
3 6
10 5
9 2
8 1
[Sample output]
47
[Evaluation use case scale and agreement]
For 40% of the evaluation use cases, 1 ≤ N, M ≤ 1000;
test question I: skill upgrade 14
Thirteenth 1st Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C
For 60% of the evaluation cases, 1 ≤ N ≤ 104, 1 ≤ M ≤ 107;
for all evaluation cases, 1 ≤ N ≤ 105, 1 ≤ M ≤ 2 × 109, 1 ≤ Ai, Bi ≤ 106.
Question I: Skill Upgrade 15
The 13th Blue Bridge Cup Competition Software Competition Provincial Competition C/C++ University Group C

Question J: Repeated Numbers

Time limit: 1.0s Memory limit: 256.0MB Total score of this question: 25 points
[Problem description]
Given a sequence A = (a1, a2, · · ·, an), give several queries, each time a certain interval [
How many numbers appear exactly ki times in li, ri] .
[Input format]
The first line of input contains an integer n indicating the length of the sequence.
The second line contains n integers a1, a2, · · ·, an, which represent the numbers in the sequence.
The third line contains an integer m representing the number of queries. The next m lines describe the query, and the i-th line contains three integers li, ri, ki indicating how many times ki occur in the interval
[li, ri] of the query . [Output format] Output m lines, corresponding to the answers of each query. [Sample input] 3 1 2 2 5 1 1 1 1 1 2 1 2 1 1 2 2 1 3 2 [Sample output] 1 Question J: The number of repetitions 16 The 13th Blue Bridge Cup Software Competition Provincial Competition C/C++ University Group C 0201 [Evaluation case scale and agreement] For 20% of the evaluation cases, n, m ≤ 500, 1 ≤ a1, a2, · · ·, an ≤ 1000; for 40% of the evaluation cases, n, m m ≤ 5000;



















For all evaluation cases, 1 ≤ n, m ≤ 100000, 1 ≤ a1, a2, , an ≤ 100000, 1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ n.
Item J: Repeated number 17

Answer

It is not an official answer, it is the answer of bloggers in the competition, it is not absolutely correct, it is for reference only

Answer to Question A:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    
	char str[] = "WHERETHEREISAWILLTHEREISAWAY";
	printf("%s\n",str);
	printf("%d\n",strlen(str));
	sort(str,str+strlen(str));
	printf("%s",str);
	return 0;
} 

Answer to Question B:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    
    
	int nian = 1;
	int yueri = 101;
	int shijian = 0;
	int out=0;
	while(!(nian==2022 && yueri==409))
	{
    
    
		if(shijian%100>59)
			shijian = (shijian/100)*100+100;
		if(shijian/100>23)
			shijian = 0,yueri++;
		if(yueri%100>30)
			yueri = (yueri/100)*100+101;
		if(yueri/100>12)
			yueri = 101,nian++;
		
		
		int count_nian[10]={
    
    0,0,0,0,0,0,0,0,0,0};
		int n1,n2,n3,n4,ok_nian=0,i;
		n1 = nian/1000;
		n2 = nian%1000/100;
		n3 = nian%100/10;
		n4 = nian%10;
		count_nian[n1]++;
		count_nian[n2]++;
		count_nian[n3]++;
		count_nian[n4]++;
		for(i=0;i<10;i++)
			if(count_nian[i]==3)
				ok_nian=1;
		if(!ok_nian)
		{
    
    
			yueri=101;
			shijian=0;
			nian++;
			continue;
		}
		 
		int count_yue[10]={
    
    0,0,0,0,0,0,0,0,0,0};
		int y1,y2,y3,y4,ok_yue=0;
		y1 = yueri/1000;
		y2 = yueri%1000/100;
		y3 = yueri%100/10;
		y4 = yueri%10;
		count_yue[y1]++;
		count_yue[y2]++;
		count_yue[y3]++;
		count_yue[y4]++;
		for(i=0;i<10;i++)
			if(count_yue[i]==3)
				ok_yue=1;
		if(!ok_yue)
		{
    
    
			shijian=0;
			yueri++;
			continue;
		}
		
		int count_shijian[10]={
    
    0,0,0,0,0,0,0,0,0,0};
		int s1,s2,s3,s4,ok_shijian=0;
		s1 = shijian/1000;
		s2 = shijian%1000/100;
		s3 = shijian%100/10;
		s4 = shijian%10;
		count_shijian[s1]++;
		count_shijian[s2]++;
		count_shijian[s3]++;
		count_shijian[s4]++;
		for(i=0;i<10;i++)
			if(count_shijian[i]==3)
				ok_shijian = 1;
		if(!ok_shijian)
		{
    
    
			shijian++;
			continue;
		}
			
			
		
		y4 = yueri%10;
		if(y4!=0)
		{
    
    
			out++;
			printf("OK nian:%4d, yueri:%4d, shijian:%4d\n",nian,yueri,shijian);
		}
		shijian++;
	}
	printf("\n\nout:%d",out); 
	return 0;
} 















Answer to Question C:

#include <bits/stdc++.h>
using namespace std;

struct ST{
    
    
	int chang,kuan;
}arr[10];

int main()
{
    
    
	arr[0].chang = 1189;
	arr[0].kuan = 841;
	int i;
	for(i=1;i<10;i++)
	{
    
    
		arr[i].kuan = arr[i-1].chang/2;
		arr[i].chang = arr[i-1].kuan;
	}
	int in;
	getchar();
	scanf("%d",&in);
	printf("%d\n%d",arr[in].chang,arr[in].kuan);
	return 0;
} 

Answer to question D:

#include <bits/stdc++.h>
using namespace std;

int arr[200000]={
    
    0};
int main()
{
    
    
	long long out=0;
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
		{
    
    
			if(i==j)
				break;
			out+=arr[i]*arr[j];
		}
	printf("%lld",out);
	return 0;
} 

Answer to Question E:

#include <bits/stdc++.h>
using namespace std;

struct ST{
    
    
	int value;
	short shuwei;
}arr[1000010];


bool cmp(struct ST a,struct ST b)
{
    
    
	if(a.shuwei==-1)
	{
    
    
		a.shuwei=0;
		a.shuwei += a.value/1000000;
		a.shuwei += a.value%1000000/100000;
		a.shuwei += a.value%100000 /10000;
		a.shuwei += a.value%10000  /1000;
		a.shuwei += a.value%1000   /100;
		a.shuwei += a.value%100   /10;
		a.shuwei += a.value%10;
		arr[a.value].shuwei = a.shuwei;
	}
	
	if(b.shuwei==-1)
	{
    
    
		b.shuwei=0;
		b.shuwei += b.value/1000000;
		b.shuwei += b.value%1000000/100000;
		b.shuwei += b.value%100000 /10000;
		b.shuwei += b.value%10000  /1000;
		b.shuwei += b.value%1000   /100;
		b.shuwei += b.value%100   /10;
		b.shuwei += b.value%10;
		arr[b.value].shuwei = b.shuwei;
	}
		
	if(a.shuwei != b.shuwei)
		return a.shuwei<b.shuwei;
	else
		return a.value<b.value;
}
int main()
{
    
    
	int i,j,n,m;
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=1;i<=n;i++)
	{
    
    
		arr[i].shuwei=-1;
		arr[i].value = i;
	}
	sort(arr+1,arr+n+1,cmp);
	//for(i=1;i<=n;i++)
//		printf("shuwei:%hd  value:%d\n",arr[i].shuwei,arr[i].value);
	printf("%d",arr[m].value);
	return 0;
} 














Answer to question F:

#include <bits/stdc++.h>
using namespace std;

long long arr[100010]={
    
    0};
char arr_out[100010]={
    
    0};//m,1yes
int main()
{
    
    
	int n,m,i,j,k;
	long long x;
	scanf("%d %d %lld",&n,&m,&x);
	for(i=1;i<=n;i++)
		scanf("%lld",&arr[i]);
		
	for(k=0;k<m;k++)
	{
    
    
		int l,r;
		scanf("%d %d",&l,&r);
		for(i=l;i<r;i++)
		{
    
    
			int should_break_yes=0;
			for(j=i;j<=r;j++)
			{
    
    
				if(i==j)
					continue;
				if((arr[i]^arr[j])==x)
				{
    
    
					should_break_yes=1;
					arr_out[k]=1;
//					printf("arri:%lld,arrj:%lld,arr[i]^arr[j]: %lld  ,x:%lld\n",arr[i],arr[j],arr[i]^arr[j],x);
					break;
				}
			}
			if(should_break_yes)
				break;
		}
	}
	
	for(k=0;k<m-1;k++)
		if(arr_out[k])
			printf("yes\n");
		else
			printf("no\n");
			
	if(arr_out[k])
			printf("yes");
		else
			printf("no");
	
	return 0;
} 

Answer to Question G:

#include <bits/stdc++.h>
using namespace std;

//char str = [1000010];
const long long pow264 = (long long)pow(2.0,64.0);
string str;
int del[1000010] = {
    
    0};
int del_len=0;

bool cmp(int a,int b)
{
    
    
	return a<b;
}
int main()
{
    
    
	long long i,j,k;
	cin>>str;
	for(k=0;k<pow264;k++)
	{
    
    
//		cout<<str<<"\n\n";
		int have_erase = 0;
		del_len = 0;
		for(i=1;i<str.length()-1;i++)
		{
    
    
			if((str[i-1]==str[i])&&(str[i]!=str[i+1]))
			{
    
    
				 del[del_len++] = i;
				 del[del_len++] = i+1;
				 have_erase = 1;
			}
			if((str[i-1]!=str[i])&&(str[i]==str[i+1]))
			{
    
    
				 del[del_len++] = i-1;
				 del[del_len++] = i;
				 have_erase = 1;
			}
		}
		
		sort(del,del+del_len+1,cmp);
		while(del_len>=1)
		{
    
    
			cout<<del[del_len]<<"\n";
			if(del[del_len]<str.length())
				str.erase(del[del_len--],1);
			else
				del_len--;
		}
		
		if(!have_erase || str.length()<=1)
			break;
	}
	if(str.length()>0)
		cout<<str;
	else
		cout<<"EMPTY";
		
	return 0;
} 

Guess you like

Origin blog.csdn.net/weixin_47964723/article/details/124064440