2020 Blue Bridge Cup Provincial Competition Group B C++ (Game 1) Real Questions

1. Running training (5 points)

Xiao Ming is going to do a running training.

At the beginning, Xiao Ming is full of physical strength, and his physical strength is calculated as 10,000. If Xiao Ming runs, he loses every minute

600 stamina. If Xiao Ming rests, he will increase his physical strength by 300 per minute. The loss and increase of physical strength are both

Evenly changing.

Xiao Ming intends to run for one minute, rest for one minute, run for another minute, and rest for another minute...and so on

ring. If Xiao Ming's physical strength reaches zero at some point, he will stop exercising.

How long will Xiao Ming stop exercising? To make the answer an integer, please output the answer in seconds.

Only fill in the number and not the unit in the answer.

Answer: 3880

2. Anniversary (5 points)

July 1, 2020 is the 99th anniversary of the founding of the Communist Party of China.

The Communist Party of China was founded on July 23, 1921.

May I ask for a total package from 12:00 noon on July 23, 1921 to 12:00 noon on July 1, 2020

How many minutes does it contain?

Answer: 52,038,720

3. Combined test (10 points)

The new crown epidemic is caused by the new crown virus and has recently spread in country A. In order to control the epidemic as soon as possible,

Prepare a large number of people for viral nucleic acid testing. However, kits for testing are in short supply.

In order to solve this difficulty, scientists thought of a way: combined testing. Coming from multiple people ( k

A) The collected specimens are put in the same kit for testing. If the result is negative, it means this k

All individuals are negative, and k individuals have been tested with one kit . If the result is positive, it means

At least one person is positive, and all the samples of these k persons need to be independently tested again (theoretically,

If kk 1 person is negative before the test, it can be inferred that the k-th person is positive, but in actual operation

This inference will not be used, but k individuals will be tested independently), plus the initial combined test, a total of

A k + completed. 1 reagent cartridge k individual detector.

Country A estimates that the infection rate of the tested people is about 1%, which is evenly distributed. How much can k take

The most economical kit?

Suppose that country A has n people, and there are n/100 infected people

Each group of k people, a total of n/k groups, sharing n/k bottles of reagents. According to the worst case, k bottles of reagents are used for every additional infected person, so n/k+(n/100)*k bottles of reagents are shared

n is a fixed value, so find the minimum (1/k+k/100)

Since a+b>=2√ab if and only when a = b, take the equal sign that is 1/k=k/100, get the minimum value

Solve for k = 10

4. REPEAT program (10 points)

The attached prog.txt is a program written in a certain language.

Among them, REPEAT k represents a cycle of number k . The range of loop control is expressed by indentation,

From the next line, the continuous indentation more than the line (the previous blank is longer) is the content contained in the loop.

For example, the following snippet:

REPEAT 2:
	A = A + 4
	REPEAT 5:
		REPEAT 6:
			A = A + 5
		A = A + 7
	A = A + 8
A = A + 9

In the fragment, from the line where A = A + 4 to the line where A = A + 8 is in the first line

In the loop twice.

REPEAT 6: The line where A = A + 7 is in the REPEAT 5: loop.

A = A + 5 The actual total number of cycles is 2 × 5 × 6 = 60 times.

After the program is executed, what is the value of A?

Idea: You can build a stack to store the information of the loop, and a variable times stores the number of times the current number of lines are executed. Through the observation of the text, we found that the "level" of the current line number can be judged by the number of spaces in front of each line, and 4 spaces represent a level. If the current row level is lower than the level of the previous loop, it means that you have exited the previous loop and you can change the stack and times. Then we found that in the entire text, all numbers are unit numbers, so we can use the loop to find a number directly to extract the significant number of the line.

Answer: 241830

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

int main()
{
	string string_;
	stack<long long> stack_; 
	freopen("prog.txt", "rb", stdin);
	getline(cin, string_);//读第一行 A=0 
	long long A=0,times=1,old_counts=0;//A=0,当前倍数,老的层数 
	while(getline(cin, string_))
	{
		long long counts=0;//当前的层数,
		for(counts=0; counts < string_.size(); counts++)
		{
			//记录空格数 4个空格是一层 
			if(string_[counts] != ' ')
				break;
		}
		counts /= 4;//这句话的层数 
		while(counts < old_counts)//新层数低 则退出一层循环 pop 
		{
			times /= stack_.top();
			stack_.pop();
			old_counts--; 
		} 
		if(string_[counts*4] == 'R')//R开头就是新增循环
		{
			for(long long now=counts*4; now < string_.size(); now++)//找到数字 
			{
				if(string_[now]>='0' && string_[now]<='9')//如果是数字 
				{
					stack_.push(string_[now]-'0');
					times *= string_[now]-'0';
					old_counts++;
					break; 
				} 
			}
		} else{
			for(long long now = counts*4;now < string_.size(); now++)//找到数字 
			{
				if(string_[now] >= '0' && string_[now] <= '9')//如果是数字 
				{
					A += (string_[now]-'0') *times;
					break; 
				} 
			}
		} 
	}
	cout<<A; 
	return 0;
} 

5. Matrix (15 points)

Put 1 ∼ 2020 in a 2 × 1010 matrix. It is required that the right side in the same row is larger than the left side, and the lower side in the same column is larger than the upper side. How many options are there?

The answer is big, you only need to give the remainder of the number of plans divided by 2020.

Answer: 1340

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

int f[1020][1020];

int main()
{
    f[0][0] = 1;                                   // 两行一个数字都不放,也是一种方案
    for (int i = 0; i <= 1010; i ++)
        for (int j = 0; j <= 1010; j ++)
        {
            if(i - 1 >= j)                         // 转移前的状态也要合法,即第一行的数量不小于第二行的数量
            	f[i][j] += f[i - 1][j] % 2020;
            if(j)
            	f[i][j] += f[i][j - 1] % 2020;
        }
        
    cout << f[1010][1010] << endl;   
    return 0;
}

6. Dividing sequence (15 points)

Problem Description

There is a sequence, the first number of the sequence is n , and each number after that is the previous number divisible by 2, please enter

Get the items with positive values ​​in this sequence.

Input format

The input line contains an integer n .

Output format

Output one line, containing multiple integers, separated by a space between adjacent integers, indicating the answer.

Sample input

20

Sample output

20 10 5 2 1

Test Data

For 80% of the evaluation use cases, 1 ≤ n ≤ 10^9

For all evaluation use cases, 1 ≤ n ≤ 10^18

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin>>n;
	cout<<n;
	while(n/2){
		cout<<' '<<n/2;
		n /= 2;
	}
	return 0;
}

7. Decoding (20 points)

Problem Description

Xiao Ming has a long string of English letters, which may contain uppercase and lowercase letters.

In this string of letters, many consecutive letters are repeated. Xiao Ming thought of a way to combine this string of alphabets

Achieve shorter: write several consecutive identical letters in the form of letters + number of occurrences.

For example, for 5 consecutive as, namely aaaaa, Xiao Ming can be abbreviated as a5 (or a4a,

aa3a etc.). For this example: HHHellllloo, Xiao Ming can be abbreviated as H3el5o2. For convenience

Da, Xiao Ming will not write more than 9 consecutive identical characters in abbreviated form.

Now give the abbreviated string, please help Xiao Ming to restore it to the original string.

Input format

The input line contains a string.

Output format

Output a string, which represents the restored string.

Sample input

H3el5o2

Sample output

HHHellllloo

Test Data

For all evaluation cases, the string consists of uppercase and lowercase English letters and numbers, and the length does not exceed

100。

Please note that the length of the original string may exceed 100.

#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	getline(cin, s);
	int len = s.length();
	int index = 0;
	while(s[index] >= '0' && s[index] <= '9'){
		cout<<s[index++];		
	}
	for(int i = index; i < len; i++){
		if(s[i] < '0' || s[i] > '9'){
			cout<<s[i];
		} else{
			if(s[i-1] < '0' || s[i-1] > '9'){
				for(int j = (s[i] - '0')-1; j > 0; j--){
					cout<<s[i-1];
				}
			}else{
				cout<<s[i];
			}
		}
	}
	return 0;
}

8. Walk the squares (20 points)

Problem Description

There are some two-dimensional lattices on the plane.

The numbering of these points is like the numbering of a two-dimensional array, from top to bottom from the first to the nth row,

From left to right, it is the 1st to the mth column. Each point can be represented by a row number and a column number.

Now someone is standing in the first row and the first column and has to go to the n-th row and m- th column. Can only go right or down

go.

Note that if the row number and column number are both even numbers, you cannot enter this grid.

Ask how many options are there.

Input format

The input line contains two integers n , m .

Output format

Output an integer to indicate the answer.

Sample input

3 4

Sample output

2

Sample input

6 6

Sample output

0

Test Data

For all evaluation use cases, 1 ≤ n ≤ 30, 1 ≤ m ≤ 30.

#include<bits/stdc++.h>
using namespace std;
int n, m;
int vis[31][31];
int res = 0;

void dfs(int x, int y){
	if(x == n && y == m){
		res++;
		return;
	}
	int next[4][2] = {
   
   {0, 1}, {1, 0}};
	for(int i = 0; i < 2; i++){
		int tx = x + next[i][0];
		int ty = y + next[i][1];
		
		if(tx <= 0 || tx > n || ty <= 0 || ty > m || (tx%2 == 0 && ty%2 == 0)){
			continue;
		}
		if(!vis[tx][ty]){
			vis[tx][ty] = 1;
			dfs(tx, ty);
			vis[tx][ty] = 0;
		}
	}
}

int main(){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			vis[i][j] = 0;
		}
	}
    cin>>n>>m;
    if(n%2 == 0 && m%2 == 0){
    	cout<<"0";
    	return 0;
	}
	dfs(1, 1);
	cout<<res;
    return 0;
}

9. Integer splicing (25 points)

Problem Description

Define an array A 1, A 2, · · ·, An of length n . You can choose two numbers Ai and Aj

( i is not equal to j ), then join Ai and Aj one after the other into a new integer. For example, 12 and 345 can be

To spell 12345 or 34512. Note that the order of exchanging Ai and Aj is always regarded as two spellings, even if

When Ai = Aj .

Please calculate how many spellings satisfy that the integer spelled out is a multiple of K.

Input format

The first line contains two integers n and K .

The second line contains n integers A 1, A 2, · · ·, An .

Output format

An integer represents the answer.

Sample input

4 2

1 2 3 4

Sample output

6

Evaluation use case scale and conventions

For 30% of the evaluation cases, 1 ≤ n ≤ 1000, 1 ≤ K ≤ 20, 1 ≤ Ai ≤ 104.

For all evaluation use cases, 1 ≤ n ≤ 105 , 1 K ≤ 105 , and 1 Ai ≤ 109.

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

int ping(int a, int b){
	int len = 0;
	int temp = b;
	while(temp){
		len++;
		temp /= 10;
	}
	return a*pow(10, len) + b;
}

int main(){
	int n, k;
	cin>>n>>k;
	int s[n];
	for(int i = 0; i < n; i++){
		cin>>s[i];
	}
	int sum = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			if(ping(s[i], s[j]) % k == 0){
				sum++;
			}
			if(ping(s[j], s[i]) % k == 0){
				sum++;
			}
		}
	}
	cout<<sum;
    return 0;
}

10. Network analysis (25 points)

Problem Description

Xiao Ming is doing a network experiment.

He set up n computers, called nodes, for sending, receiving and storing data.

Initially, all nodes are independent and there is no connection.

Xiao Ming can connect two nodes through a network cable, and the two nodes can communicate with each other after connection

Up. If two nodes are connected by a network cable, they are called adjacent.

Xiao Ming sometimes tests the network at that time, he will send a message at a certain node, and the message will be sent

To each adjacent node, and then these nodes will be forwarded to their adjacent nodes, until all direct

Or indirectly adjacent nodes have received the information. All sending and receiving nodes will store the information.

A piece of information is stored only once.

Given the process of Xiaoming's connection and testing, please calculate the size of the information stored in each node.

Input format

The first line of input contains two integers n and m , which represent the number of nodes and the number of operations respectively. Node from

Numbers from 1 to n .

In the next m lines, three integers in each line represent an operation.

If the operation is 1 ab , it means that node a and node b are connected by a network cable. When a = b

When, it means that a self-loop is connected, which has no substantial impact on the network.

If the operation is 2 pt , it means that a message of size t is sent on node p .

Output format

Output a line, containing n integers, separated by a space between adjacent integers, indicating progress in turn

The size of the information stored on node 1 to node n after the above operations .

Sample input

4 8

1 1 2

2 1 10

2 3 5

1 4 1

2 2 2

1 1 2

1 2 4

2 2 1

Sample output

13 13 5 3

Test Data

For 30% of the evaluation cases, 1 ≤ n ≤ 20 and 1 ≤ m ≤ 100.

For 50% of the evaluation cases, 1 ≤ n ≤ 100 and 1 m ≤ 1000.

For 70% of the evaluation cases, 1 ≤ n ≤ 1000 and 1 m ≤ 10000.

For all evaluation cases, 1 ≤ n ≤ 10000 , 1 m ≤ 100000 , and 1 t ≤ 100.

Idea: The core idea is to consolidate and collect. An array is used to store the old values, an array is used to store the weights of the root nodes, and an array is the father array of the combined search. When performing 2 operations, the root node of the operation value is found and weighted by the search set. When performing 1 operation, if the two numbers are in one set, no operation is performed; if the two numbers are not in the same set, all nodes are traversed, their old value arrays are added to the weight of the root node, and then the union is performed operating. Remember to clear the weight array to prevent repeated calculations later.

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

int old_[10001],new_[10001],father[10001],n,m;//存老值 存根节点新值 父节点数组 

int find(int a)
{
	return father[a]==a ? a : father[a]=find(father[a]);//路径压缩
}

void union_(int a,int b)
{
	int temp_a=find(a),temp_b=find(b);
	if(temp_a!=temp_b)
	{
		for(register int now=1;now<=n;now++)
		{
			old_[now]+=new_[find(now)];//旧值数组遍历加上权值
		}
		memset(new_,0,sizeof(new_));//重置权值数组,防止重复计算
		father[temp_a]=temp_b;
	}
}

int main()
{
	int a,b,c;
	memset(new_,0,sizeof(new_));
	for(register int now=1;now<=10000;now++)
	{
		father[now]=now;//father数组初始化 
	} 
	scanf("%d %d",&n,&m);
	while(m--)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(a==1)
		{
			union_(b,c);
		}
		else
		{
			new_[find(b)]+=c;
		}
	} 
	for(register int now=1;now<=n;now++)
	{
		printf("%d ",old_[now]+new_[find(now)]);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44723496/article/details/109046825