Ninth Blue Bridge Cup Contest Finals (Software category) questions \ C University Group B - 2018 Nian

1、

Title: change LingChao

x planet banknote denomination only: 100, 5- 2, $ 1, a total of four kinds.
Xiao Ming go x Stars Tours, his hand only 2 x $ 100 star coins, too inconvenient, just passing through x Star Bank enchant change.
Zhang Xiaoming number a little obsessive-compulsive disorder, he insisted that 200 yuan Ling Chao swapped out in just $ 2 $ 1 10 times the number of sheets,
the rest of the course is 5 yuan denomination.

Bank staff a bit difficult, you can help calculate: Xiao Ming in the premise of meeting the requirements, at least give him want to change how many bills you?
($ 5 2, $ 1 denomination must have, is not 0)

Note that you need to submit is an integer, do not fill in any extra content.

//换零钞
#include<stdio.h>
int main(){
	int i,sum = 0;
	for(i=1;i<10;i++){	//i:一元的个数 
		if((200- (21*i))%5 == 0){
			sum = 11*i +((200-(21*i) )/5);
			break;
		}
	}
	printf("%d",sum);
	return 0;
} 

  

2.
Title: Laser Style

x To increase the planet's grand festival atmosphere, lined with 30 machine light, a beam of light shot into space.
When installation is found, for unknown reasons, the adjacent two lasers can not be opened at the same time!
King would like to know, in the current circumstances this bug exists, how many kinds of laser effects can play altogether?

Obviously, if only three machines, can total into five styles, namely:
all shut (sorry, at this time silence speaks, which is considered a)
to open a total of three kinds of
open two, only one kind

30 bad Well, the king had to make you useful.

Requested an integer representing the number of kinds of pattern 30 can be formed of a laser.

Note, submit only one integer, do not fill in any extra content.

//激光样式
#include<stdio.h>
int fun(int n){
	if(n == 1)
		return 2;
	else if(n == 2)
		return 3;
	else
	 return fun(n-1) + fun(n-2);  
}
int main(){
	int num = 0;
	num = fun(30);
	printf("%d",num);
	return 0; 
} 
Laser // Style 
// dynamic programming DP [i] is closed when style number [0] is the i-th light DP [i] when the number of patterns [1] of the i-th lamp turn 
 #include <stdio.h> 
 int DP [100] [2]; 
 int main () { 
 	int n-= 30, I; 
 	DP [0] [0] =. 1; 
 	DP [0] [. 1] =. 1; 
 	for (I =. 1; I <n-; I ++) { 
 		DP [I] [0] + = DP [I-. 1] [0] + DP [I-. 1] [. 1]; 
 		DP [I] [. 1] + = DP [I-. 1] [0] ; 
	} 
	the printf ( "% D", DP [n--. 1] [0] + DP [. 1-n-] [. 1]); 
	return 0; 
}

  

3、

Title: Gray code

Gray code is a binary n bits to represent numbers.
Ordinary binary representation is different is that it requires only two adjacent numbers of different digits 1.
And last two figures also requires only a difference of one.

There are many algorithms to generate a Gray code. The following is a more common one:
to start generating from the coded all zeros.
When generating the odd number, only the last bit of the digital current changes (becomes 0 becomes 0 1,1)
when a first even number, first find a rightmost 1, the digital change its left.
4 Gray code sequence generated by the rule as follows:
0000
0001
0011
0010
0110
0111
0101
0100
1100 is
1101
1111
1110
1010
1011
1001
1000

The following is the implementation code, wherein the logic careful analysis and fill the missing codes underlined.

#include <stdio.h> 
void Show (A int, int n-) 
{ 
	int I; 
	int = MSK. 1; 
	for (I = 0; I <-n-. 1; I ++) 
		MSK MSK = <<. 1; 
	for (I = 0; I <n-; I ++) { 
		the printf ((A & MSK) ". 1":? "0"); 
		MSK = MSK >>. 1; 
	} 
	the printf ( "\ n-"); 
} 
void F (int n-) / / n: number of binary digits 
{ 
	int I; 
	int NUM =. 1; 
	for (I = 0; I <n-; I ++) 
		NUM = NUM <<. 1; // num * 2 num left a maximum left four bits 16 
	int A = 0; 
	for (I = 0; I <NUM; I ++) {// NUM results 
		Show (A, n-); // 
		IF (I% 2 == 0) { 
			A = A ^. 1 ; // 
		} 
		the else { 
			A = A ^ ((A & -a) <<. 1);/ * _________________________ * /; // fill in the blank / * _________________________ * /; // fill in the blank 
		}
	}
}

int main()
{
	f(4);
	return 0;
}

  

Please note: only need to fill out the underlined the lack of content, not copying existing code or symbol.

4、

Title: tone Watch

Xiao Ming bought a high-end atmosphere on the grade of electronic watches, he is preparing to transfer time yet.
M78 in different units of measurement nebula, time and earth, the n-nebula minutes to one hour M78.
As we all know, there is only one button to watch the current number plus one. In tune minutes to go, if the currently displayed number is 0, then click the button turns 1, press again becomes 2. If the current number is n - 1, after press will become zero.
As OCD, Xiao Ming must take the time to watch the tone right. If the time on your watch more than 1 than the current time, the Yaoan n - 1 plus one button can be transferred back to the correct time.
Xiao Ming think, if the watch can add a button to indicate the current number plus k nice ah ......
he wondered if this had + k button and follow the optimal strategy button, transferred to another from any of a number of minutes any of a number of minutes shall be according to the most times.
Note that, when the press button + k, the k numbers if added over n-1, will be on the modulo n.
For example, n = 10, k = 6, when assumed that the current time is 0, double-click button 2 + k is adjusted to 2.

"Input format"
line of two integers n, k, meaning such as the title.

"Output Format"
line of an integer
, said: according to optimal strategy button, transferred from one time to another time shall be according to the most times.

"Sample input"
53

"Sample Output"
2

"Sample explained,"
If the time is correct press 0 times. Otherwise, the relationship between the number and the series of operations Yaoan follows:
1: +1
2: +1, +1
3: +3
4: +3, +1

"Data range"
of 30% of the data 0 <K <n-<=. 5
0 <K <n-<= 100 for the 60% of data
100% of data 0 <k <n <= 100000

Resources for:
peak memory consumption (including virtual machines) <256M
the CPU consumption <1000ms

Please strictly follow the requirements of output, not superfluous to print something like: "Please enter ..." unwanted content.

Note:
main function needs to return 0;
use only ANSI C / ANSI C ++ standard;
do not call the special function depends on the build environment or operating system.
All dependent functions must explicitly in the source file #include <xxx>
can not be provided by engineering common header is omitted.

When the submission process, pay attention to select the desired language and compiler type type.

//调手表
#include<stdio.h>
int max(int a,int b){
	return a>b?a:b;
}
int main(){
	int n,k,i,sum = 0,temp;
	scanf("%d %d",&n,&k);
	int num[n];
	for(i=1;i<n;i++){
		num[i] = 0;
		temp = i;
		while(temp > 0){
			if(temp >= k){
				temp -= k;
				num[i] += 1;
			}
			else{
				temp -= 1;
				num[i] += 1;
			}
		}
	}
	for(i=1;i<n;i++){
		sum = max(sum,num[i]); 
	}
	printf("%d",sum);
	return 0; 
} 

  5、

 

Guess you like

Origin www.cnblogs.com/Hqx-curiosity/p/11992722.html