The 4th C/C++ Group A Blue Bridge Cup Provincial Competition in 2014

Here is the topic column of the Blue Bridge Cup over the years. It will be updated successively and the real questions and answers of previous years will be released. I welcome you to follow me. Your likes and attention are the best motivation for me! ! !
The real questions are updated every day, so stay tuned

Blue Bridge Cup real questions and detailed answers over the years


Question 1: Guess the age

Topic description
Xiao Ming took his two younger sisters to the Lantern Festival. When asked how old they are, they playfully say: "Our age is 6 times the sum of our ages". Xiao Ming added: "They are not twins, and the age difference must be no more than 8 years old."
Please write: the age of Xiao Ming's younger sister.
topic analysis
topic code



Question 2: Cut noodles

Item description
A high-gluten ramen, cut a knife in the middle, you can get 2 noodles.
If you fold it in half first and cut a knife in the middle, you can get 3 noodles.
If you fold it twice in a row and cut a knife in the middle, you can get 5 noodles.
Then, if you fold it in half 10 times in a row and cut a knife in the middle, how many noodles will you get?
topic analysis
topic code



Question 3: The Magical Formula

Question Description
A multiplication formula composed of 4 different numbers, and their product is still composed of these 4 numbers.
For example:
210 x 6 = 1260
8 x 473 = 3784
27 x 81 = 2187
all meet the requirements.
If the formulas that satisfy the commutative law of multiplication are counted as the same case, then, including the three cases listed above, how many formulas are there to satisfy the requirements.
topic analysis
topic code



Question 4: Shi Fengshou Quick Calculation

Topic description
The revolutionary contribution of Shi Fengshou speed algorithm is: starting from the high point, predicting the carry. There is no need for a nine-nine table, which completely subverts the traditional hand calculation!
The core basis of quick calculation is: the multiplication of 1-digit multiplied by multiple digits.
Among them, multiplying by 7 is the most complicated, just take it as an example.
Because, 1/7 is a recurring decimal: 0.142857..., if the number of digits exceeds 142857..., it is necessary to enter 1
for the same reason, 2/7, 3/7, ... 6/7 are also similar recurring decimals, multi-digit If it exceeds n/7, it is necessary to enter n
The following program simulates the operation process of multiplying by 7 in the Shi Fengshou algorithm.
The rules for multiplying by 7 are as follows: multiply an even number by 2, multiply an odd number by 2 and add 5, and only take the one place.
The carry rule of multiplying by 7 is:
full 142857… forward 1,
full 285714… forward 2,
full 428571… forward 3,
full 571428… forward 4,
full 714285… forward 5,
full 857142… forward 6
, please analyze the program flow and fill in the plan The missing code in the line section.

//计算个位 
int ge_wei(int a)
{
    
    
	if(a % 2 == 0)
		return (a * 2) % 10;
	else
		return (a * 2 + 5) % 10;	
}

//计算进位 
int jin_wei(char* p)
{
    
    
	char* level[] = {
    
    
		"142857",
		"285714",
		"428571",
		"571428",
		"714285",
		"857142"
	};
	
	char buf[7];
	buf[6] = '\0';
	strncpy(buf,p,6);
	
	int i;
	for(i=5; i>=0; i--){
    
    
		int r = strcmp(level[i], buf);
		if(r<0) return i+1;
		while(r==0){
    
    
			p += 6;
			strncpy(buf,p,6);
			r = strcmp(level[i], buf);
			if(r<0) return i+1;
			______________________________;  //填空
		}
	}
	
	return 0;
}

//多位数乘以7
void f(char* s) 
{
    
    
	int head = jin_wei(s);
	if(head > 0) printf("%d", head);
	
	char* p = s;
	while(*p){
    
    
		int a = (*p-'0');
		int x = (ge_wei(a) + jin_wei(p+1)) % 10;
		printf("%d",x);
		p++;
	}
	
	printf("\n");
}

int main()
{
    
    
	f("428571428571");
	f("34553834937543");		
	return 0;
}

topic analysis
topic code



Question 5: Championship

Topic description
If you want to select the first and second largest data among n data (requires the location and value of the output data), what method is used to compare the least number of times? We can take inspiration from sports championships.

As shown in Figure [1.png], in a tournament with 8 players, firstly, they will compete in pairs, and half of them will be eliminated. The winners compete in pairs...until the first place is decided.

After the first place is out, just re-race the position marked in yellow.

The code below implements this algorithm (assuming there are no identical values ​​in the data).

In the code, an array needs to be used to represent the tree in the figure (note that this is a full binary tree, and the shortage needs to be filled). It does not store the data itself, but stores the subscript of the data.

After the first data output, its position is marked as -1

//重新决出k号位置,v为已输出值 
void pk(int* a, int* b, int n, int k, int v)
{
    
    
	int k1 = k*2 + 1;
	int k2 = k1 + 1;
	
	if(k1>=n || k2>=n){
    
    
		b[k] = -1;
		return;
	}
	
	if(b[k1]==v) 
		pk(a,b,n,k1,v);
	else
		pk(a,b,n,k2,v);
	
	//重新比较
	if(b[k1]<0){
    
    
		if(b[k2]>=0)
			b[k] = b[k2]; 
		else
			b[k] = -1;
		return;
	}
	
	if(b[k2]<0){
    
    
		if(b[k1]>=0)
			b[k] = b[k1]; 
		else
			b[k] = -1;
		return;
	}
	
	if(______________________) //填空
		b[k] = b[k1];
	else
		b[k] = b[k2];
}

//对a中数据,输出最大,次大元素位置和值 
void f(int* a, int len)
{
    
    
	int n = 1;
	while(n<len) n *= 2;
	
	int* b = (int*)malloc(sizeof(int*) * (2*n-1));
	int i;
	for(i=0; i<n; i++){
    
     
		if(i<len) 
			b[n-1+i] = i;
		else
			b[n-1+i] = -1;
	}
	
	//从最后一个向前处理
	for(i=2*n-1-1; i>0; i-=2){
    
    
		if(b[i]<0){
    
    
			if(b[i-1]>=0)
				b[(i-1)/2] = b[i-1]; 
			else
				b[(i-1)/2] = -1;
		}
		else{
    
    
			if(a[b[i]]>a[b[i-1]])
				b[(i-1)/2] = b[i];
			else
				b[(i-1)/2] = b[i-1];
		}
	}
	
	//输出树根
	printf("%d : %d\n", b[0], a[b[0]]);
	
	//值等于根元素的需要重新pk
	pk(a,b,2*n-1,0,b[0]);
	
	//再次输出树根
	printf("%d : %d\n", b[0], a[b[0]]);
	
	free(b);
}


int main()
{
    
    
	int a[] = {
    
    54,55,18,16,122,17,30,9,58};
	f(a,9);	
}

insert image description here

topic analysis
topic code



Question 6: Poker Sequence

Title description
AA 2 2 3 3 4 4, a total of 4 pairs of playing cards. Please line them up.
Requirements: 1 card between two aces, 2 cards between two 2s, 3 cards between two 3s, and 4 cards between two 4s.
Please fill in all the permutations that meet the requirements, the one with the smallest lexicographical order.
For example: 22AA3344 is lexicographically smaller than A2A23344. Of course, none of them are answers that suffice.
Please submit answers through your browser. "A" must not be replaced with a lowercase letter a, and "1" should not be used instead. There must be no spaces between characters.
topic analysis

topic code



Question 7: Ants catch a cold

Problem description
There are n ants on a slender straight pole 100 cm long. Some of their heads turned left and some to the right.

每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒。

当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。

这些蚂蚁中,有1只蚂蚁感冒了。并且在和其它蚂蚁碰面时,会把感冒传染给碰到的蚂蚁。

请你计算,当所有蚂蚁都爬离杆子时,有多少只蚂蚁患上了感冒。

【Data Format】

第一行输入一个整数n (1 < n < 50), 表示蚂蚁的总数。

接着的一行是n个用空格分开的整数 Xi (-100 < Xi < 100), Xi的绝对值,表示蚂蚁离开杆子左边端点的距离。正值表示头朝右,负值表示头朝左,数据中不会出现0值,也不会出现两只蚂蚁占用同一位置。其中,第一个数据代表的蚂蚁感冒了。

要求输出1个整数,表示最后感冒蚂蚁的数目。

For example, input:
3
5 -2 8 The
program should output:
1

For another example, input:
5
-10 8 -20 12 25 The
program should output:
3

Resource convention:
peak memory consumption < 256M
CPU consumption < 1000ms

topic analysis
topic code



Question 8: Treasure from the Underground Palace

Title Description
King X has an underground treasury. is a matrix of nxm lattices. Put one treasure in each cell. Each baby has a value sticker attached.
The entrance to the underground palace is in the upper left corner and the exit is in the lower right corner.
Xiao Ming was taken to the entrance of the underground palace, and the king asked him to walk only to the right or down.
When walking through a certain grid, if the value of the treasure in that grid is greater than that of any treasure in Xiao Ming's hand, Xiao Ming can pick it up (of course, he can also not take it).
When Xiaoming walks to the exit, if the treasures in his hand are exactly k, these treasures can be given to Xiaoming.
Please help Xiao Ming calculate how many different action plans he has to obtain these k treasures in a given situation.
[Data format]
Enter a line of 3 integers, separated by spaces: nmk (1<=n,m<=50, 1<=k<=12)
Next, there are n lines of data, each line has m integers Ci (0 <=Ci<=12) represents the value of the treasure on this grid. It is
required to output an integer, indicating the number of action plans to take exactly k treasures. The number can be large, print it modulo 1000000007.

For example, input:
2 2 2
1 2
2 1
The program should output:
2

For another example, input:
2 3 2
1 2 3
2 1 5
The program should output:
14

Resource convention:
peak memory consumption < 256M
CPU consumption < 1000ms
problem analysis
problem code



Question 9: Fibonacci

Topic Description
The Fibonacci sequence is familiar to everyone. Its definition is:
f(x) = 1 … (x=1,2)
f(x) = f(x-1) + f(x-2) … (x>2)
for a given integer n and m, we wish to evaluate:
f(1) + f(2) + … + f(n). But this value can be very large, so we take it modulo f(m).
For the formula, see [Figure 1.png]
, but this number is still very large, so it is necessary to modulo p again.
[Data format]
The input is a line of integers separated by spaces nmp (0 < n, m, p < 10^18)
The output is 1 integer

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

For another example, input:
15 11 29 The
program should output:
25

Resource convention:
peak memory consumption < 256M
CPU consumption < 1000ms
insert image description here

topic analysis
topic code



Question 10: Volatility Sequence

Problem Description
Observe this sequence:
1 3 0 2 -1 1 -2 ...
The last item in this sequence is always 2 more or 3 less than the previous item.
Dongdong is very curious about this kind of sequence. He wants to know how many integer sequences of length n and s are possible, and the latter term always increases by a or decreases by b compared to the previous term?
[Data format]
The first line of input contains four integers nsab, the meaning is as described above.
Output a line containing an integer representing the number of scenarios that satisfy the condition. Since this number is very large, please output the remainder of dividing the scheme number by 100000007.
For example, input:
4 10 2 3 The
program should output:
2
[Example description]
The two sequences are 2 4 1 3 and 7 4 1 -2 respectively.
[Data scale and convention]
For 10% of the data, 1<=n<=5, 0<=s<=5, 1<=a, b<=5;
for 30% of the data, 1<=n<= 30, 0<=s<=30, 1<=a,b<=30;
for 50% of the data, 1<=n<=50, 0<=s<=50, 1<=a,b<= 50;
for 70% of the data, 1<=n<=100, 0<=s<=500, 1<=a, b<=50;
for 100% of the data, 1<=n<=1000, -1,000,000,000 <=s<=1,000,000,000, 1<=a, b<=1,000,000.
Resource Convention:
Peak Memory Consumption <


topic code



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774873&siteId=291194637