[Blue Bridge Cup] Exam Questions Training-Analysis of the 8th Lanqiao Cup Provincial C/C++ University Group B Exam Questions

first question

    小明刚刚找到工作,老板人很好,只是老板夫人很爱购物。老板忙的时候经常让小明帮忙到商场代为购物。小明很厌烦,但又不好推辞。

    这不,XX大促销又来了!老板夫人开出了长长的购物单,都是有打折优惠的。
    小明也有个怪癖,不到万不得已,从不刷卡,直接现金搞定。
    现在小明很心烦,请你帮他计算一下,需要从取款机上取多少现金,才能搞定这次购物。

    取款机只能提供100元面额的纸币。小明想尽可能少取些现金,够用就行了。
    你的任务是计算出,小明最少需要取多少现金。

以下是让人头疼的购物单,为了保护隐私,物品名称被隐藏了。
-----------------
****     180.90       88折
****      10.25       65折
****      56.14        9折
****     104.65        9折
****     100.30       88折
****     297.15        半价
****      26.75       65折
****     130.62        半价
****     240.28       58折
****     270.62        8折
****     115.87       88折
****     247.34       95折
****      73.21        9折
****     101.00        半价
****      79.54        半价
****     278.44        7折
****     199.26        半价
****      12.97        9折
****     166.30       78折
****     125.50       58折
****      84.98        9折
****     113.35       68折
****     166.57        半价
****      42.56        9折
****      81.90       95折
****     131.78        8折
****     255.89       78折
****     109.17        9折
****     146.69       68折
****     139.33       65折
****     141.16       78折
****     154.74        8折
****      59.42        8折
****      85.44       68折
****     293.70       88折
****     261.79       65折
****      11.30       88折
****     268.27       58折
****     128.29       88折
****     251.03        8折
****     208.39       75折
****     128.88       75折
****      62.06        9折
****     225.87       75折
****      12.89       75折
****      34.28       75折
****      62.16       58折
****     129.12        半价
****     218.37        半价
****     289.69        8折
--------------------

需要说明的是,88折指的是按标价的88%计算,而8折是按80%计算,余者类推。
特别地,半价是按50%计算。

请提交小明要从取款机上提取的金额,单位是元。
答案是一个整数,类似4300的样子,结尾必然是00,不要填写任何多余的内容。

Answer: 5200

Calculation

#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	double res = (180.90* 0.88 + 
10.25 * 0.65 +
56.14* 0.9 +
104.65*0.9+
100.30* 0.88+
297.15*0.5+
26.75* 0.65+
130.62*0.5+
240.28* 0.58+
270.62*0.8+
115.87*0.88+
247.34* 0.95+
73.21* 0.9+
101.00*0.5+
79.54*0.5+
 278.44* 0.7+
 199.26* 0.5+
12.97*0.9+
166.30*0.78+
125.50*0.58+
84.98*0.9+
113.35*0.68+
166.57*0.5+
42.56*0.9+
81.90*0.95+
131.78*0.8+
255.89*0.78+
109.17*0.9+
 146.69*0.68+
139.33*0.65+
141.16*0.78+
154.74*0.8+
59.42*0.8+
 85.44* 0.68+
293.70* 0.88+
261.79* 0.65+
11.30*0.88+
268.27*0.58+
128.29*0.88+
 251.03* 0.8+
208.39* 0.75+
128.88* 0.75+
 62.06* 0.9+
225.87* 0.75+
12.89*0.75+
34.28* 0.75+
62.16* 0.58+
 129.12*0.5+
218.37*0.5+
289.69*0.8);
cout << res;
	return 0;
}

Second question

2,3,5,7,11,13,... is a sequence of prime numbers.
Similar: 7,37,67,97,127,157 This arithmetic sequence composed entirely of prime numbers is called arithmetic prime sequence.
The tolerance of the sequence above is 30, and the length is 6.

In 2004, Green and the Chinese Tao Zhexuan proved that there is an arithmetic sequence of prime numbers of any length.
This is an amazing achievement in the field of number theory!

Based on this theory, please use your computer to search with confidence:

What is the minimum tolerance for a prime number sequence of length 10?

Note: What needs to be submitted is an integer, do not fill in any redundant content and explanatory text.

Answer: 210

enumerate

Enumerate the tolerances instead of finding 10 arithmetic prime numbers with the same tolerance from a bunch of prime numbers. For tolerance enumeration, the tolerance is fixed, and it is judged whether the number with the tolerance as the distance is a prime number, so that it is better to handle and judge

#include <iostream>
using namespace std;

const int MAX_N = 10000;
bool prime[MAX_N];

//对前10000个数筛选素数出来 
void filter(){
	prime[1] = false;
	for(int i = 2; i < MAX_N; i++){		//对数组初始化true 
		prime[i] = true;
	}
	for(int i = 2; i < MAX_N; i++){		
		for(int j = i*2; j < MAX_N; j+=i){	 //通过倍数对素数进行筛选 
			prime[j] = false;			//如,2的倍数的数都不是素数, 
		}
	}
} 

int main(int argc, char** argv) {
	filter();
	
	for(int i = 1; i*10 < MAX_N; i++){ //枚举公差 
		for(int j = 2; j + i*10 < MAX_N; j++){	//枚举素数,从2开始 
			if(prime[j]){	//如果该数是素数 
				int d = j;	//从该项开始往后10个素数判断是否满足条件 
				int count = 1;	//计算 
				for(int k = 2; k <= 10; k++){
					if(prime[d+i]){	//对公差为i的数进行判断是否为素数,是继续, 
						d = d+i;
						count ++;
					}else{		//否直接退出,该公差不满足。 
						break;
					}
				}
				if(count == 10){
					cout << i;
				} 
			}
		}
	}
	
	return 0;
}

 

Third question 

A certain batch of precious metal materials are neatly stacked in the high-tech laboratory of Planet X.

The shape and size of each metal raw material are exactly the same, but the weight is different.
The metal materials are stacked strictly in a pyramid shape.

                             7
                            5 8
                           7 8 8
                          9 2 7 2
                         8 1 4 9 1
                        8 1 8 8 4 1
                       7 9 6 1 4 5 4
                      5 6 5 5 6 9 5 6
                     5 5 4 7 9 3 5 5 1
                    7 5 7 9 7 4 7 3 3 1
                   4 6 4 5 5 8 8 3 2 4 3
                  1 1 3 3 1 6 6 5 5 4 4 2
                 9 9 9 2 1 9 1 9 2 9 5 7 9
                4 3 3 7 7 9 3 6 1 3 8 8 3 7
               3 6 8 1 5 3 9 5 8 3 8 1 8 3 3
              8 3 2 3 3 5 5 8 5 4 2 8 6 7 6 9
             8 1 8 1 8 4 6 2 2 1 7 9 4 2 3 3 4
            2 8 4 2 2 9 9 2 8 3 4 9 6 3 9 4 6 9
           7 9 7 4 9 7 6 6 2 8 9 4 1 8 1 7 2 1 6
          9 2 8 6 4 2 7 9 5 4 1 2 5 1 7 3 9 8 3 3
         5 2 1 6 7 9 3 2 8 9 5 5 6 6 6 2 1 8 7 9 9
        6 7 1 8 8 7 5 3 6 5 4 7 3 4 6 7 8 1 3 2 7 4
       2 2 6 3 5 3 4 9 2 4 5 7 6 6 3 2 7 2 4 8 5 5 4
      7 4 4 5 8 3 3 8 1 8 6 3 2 1 6 2 6 4 6 3 8 2 9 6
     1 2 4 1 3 3 5 3 4 9 6 3 8 6 5 9 1 5 3 2 6 8 8 5 3
    2 2 7 9 3 3 2 8 6 9 8 4 4 9 5 8 2 6 3 4 8 4 9 3 8 8
   7 7 7 9 7 5 2 7 9 2 5 1 9 2 6 5 3 9 3 5 7 3 5 4 2 8 9
  7 7 6 6 8 7 5 5 8 2 4 7 7 4 7 2 6 9 2 1 8 2 9 8 5 7 3 6
 5 9 4 5 5 7 5 5 6 3 5 3 9 5 8 9 5 4 1 2 6 1 4 3 5 3 2 4 1
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X

The number represents the weight of the metal block (larger unit of measurement).
The X on the bottom layer represents 30 extremely high-precision electronic scales.

Assuming that the weight of each piece of raw material falls very accurately on the two metal blocks below, in the
end, the weight of all the metal blocks is strictly and accurately divided equally on the bottom electronic scale.
The unit of measurement of the electronic scale is very small, so the displayed number is very large.

The staff found that the reading of the electronic scale with the smallest reading was: 2086458231

Please calculate: What is the reading of the electronic scale with the largest reading?

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

Answer: 72665192664

Simulation calculation, pay attention to the change of measurement unit and the output of large numbers 

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

int main(int argc, char** argv) {
	double a[100][100];
	//录入金字塔数组,别傻傻手动输入啊!!!直接复制粘贴 
	for(int i = 1; i <= 29; i++){
		for(int j = 1; j <= i; j++){
//			cin >> a[i][j];
			scanf("%lf",&a[i][j]);
		}
	}
	
	for(int i = 2; i <= 30; i++){
		for(int j = 1; j <= i; j++){
			a[i][j] += (a[i-1][j-1]/2 + a[i-1][j]/2);
		}
	} 
	sort(a[30]+1, a[30]+31);	//记得排序,输出最大的数 
//	cout << (2086458231/a[30][1])*a[30][30];	//科学计数法需要转换 
//	注意计量单位!,所以不能直接输出啊a[30]a[30],需要根据题意转换成它的计量单位 
	printf("%lf", (2086458231/a[30][1])*a[30][30]);	//直接用printf大数格式输出 

	return 0;
}

 

Fourth question

Cut a 6x6 grid into two parts along the edge of the grid.
The shapes of the two parts are required to be exactly the same.

As shown in the figure: p1.png, p2.png, p3.png are feasible segmentation methods.

Try to calculate:
Including these three division methods, how many different division methods are there in total?
Note: Rotational symmetry belongs to the same division method.

Please submit the whole number, do not fill in any extra content or explanatory text.

Answer: 509 

#include <iostream>
using namespace std;
 
int a[7][7];
int v[7][7];
int count;

void dfs(int x, int y){
	if(x == 0 || x == 6 || y ==0 || y == 6){
		count++;
		return ;
	}
	
	v[x][y] = 1;
	v[6-x][6-y] = 1;
	
	if(v[x+1][y] == 0){
		dfs(x+1, y);
		v[x+1][y] = 0;
		v[6-(x+1)][6-y] = 0;
	} 
	if(v[x][y+1] == 0){
		dfs(x, y+1);
		v[x][y+1] = 0;
		v[6-x][6-(y+1)] = 0;
	}
	if(v[x-1][y] == 0){
		dfs(x-1, y);
		v[x-1][y] = 0;
		v[6-(x-1)][6-y] = 0;
	}
	if(v[x][y-1] == 0){
		dfs(x, y-1);
		v[x][y-1] = 0;
		v[6-x][6-(y-1)] = 0;
	}
	
}

int main(int argc, char** argv) {
	dfs(3, 3);
	cout << count / 4;
	return 0;
}

 

Fifth question

There are many ways to find the k-th digit of an integer.
The following method is one.
// Find the digit length when x is expressed in decimal system
int len(int x){     if(x<10) return 1;     return len(x/10)+1; } // Take the k-th digit of x int f(int x, int k){     if(len(x)-k==0) return x%10;     return _____________________; //fill in the blanks } int main() {     int x = 23574;     printf("%d\n ", f(x,3));     return 0; }













For the test data in the question, 5 should be printed.

Please carefully analyze the source code and add the missing code in the underlined part.

Note: Only submit the missing code, do not fill in any existing content or descriptive text.

Answer: f(x/10, k) 

#include <iostream>
using namespace std;

// 求x用10进制表示时的数位长度
int len(int x){
	if(x < 10) return 1;
	return len(x/10) + 1;
}

// 取x的第k位数字
int f(int x, int k){
	if(len(x)-k == 0) return x%10;
//	return _____________________;? //填空
	return f(x/10, k);
}
int main()
{
	int x = 23574;
	printf("%d\n", f(x, 3));
	return 0;
}

 

Sixth question

The problem of maximum common substring length is: what
is the maximum length that can be matched among all substrings of two strings.

For example: "abcdkkk" and "baabcdadabc",
the longest common substring that can be found is "abcd", so the maximum common substring length is 4.

The following program is solved by the matrix method, which is a relatively effective solution for the case where the string size is not large.

Please analyze the idea of ​​the solution, and fill in the missing code in the underlined part.
#include <stdio.h>
#include <string.h>

#define N 256
int f(const char* s1, const char* s2)
{
    int a[N][N];
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int i,j;
    
    memset(a,0,sizeof(int)*N*N);
    int max = 0;
    for(i=1; i<=len1; i++){
        for(j=1; j<=len2; j++){
            if(s1[i-1]==s2[j-1]) {
                a[i][j] = __________________________;  //填空
                if(a[i][j] > max) max = a[i][j];
            }
        }
    }
    
    return max;
}

int main()
{
    printf("%d\n", f("abcdkkk", "baabcdadabc"));
    return 0;
}

Answer: a[i-1][j-1] + 1

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

#define N 256
int f(const char* s1, const char* s2)
{
 	int a[N][N];
	int len1 = strlen(s1);
	int len2 = strlen(s2);
	int i, j;
	
	memset(a, 0, sizeof(int)*N*N);
	int max = 0;
	for(i=1; i<=len1; i++){
		for(j=1; j<=len2; j++){
			if(s1[i-1] == s2[j-1]) {
//				a[i][j] = __________________________;? //填空
				a[i][j] = a[i-1][j-1] + 1; 
				if(a[i][j] > max) 
					max = a[i][j];
			}
		}
	}
	
	return max;
}

int main()
{
	printf("%d\n", f("abcdkkk", "baabcdadabc"));
	return 0;
}

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_44566432/article/details/115001294