2019 Tenth Blue Bridge Cup group C ++ b answer section title

Questions A: team

This problem Total: 5 minutes
[Problem Description]
as a basketball coach, you need to select No. 1-5 digit number one player each from the following list,
the composition of the team's starting lineup.
When the score of each player as No. 1 to No. 5 shown in the following table. Please calculate the starting lineup 1
No. No. 5 position to the sum of the maximum possible score is how much?

Answer: 490

Ideas: direct hand calculations (Note: No. 1 to No. 5 must be different people)

Questions C: the number of columns is evaluated

The title score: 10 points
[Problem Description]
Given the number of columns 1,1,1,3,5,9,17, ..., item 4 from the start, each are the top three and. Seeking
the last 4 digits of the first 20,190,324.
[Answer] submit
this is a result of fill in the blank questions, you only need to calculate and submit the results. The results of this question is a
4-bit integer (Hint: the answer to the thousands is not 0), when submitting answers to fill in only the integer, fill in
the extra content will not score.

Answer: 4659

#include <iostream>
using namespace std;
int a[20190325]; // 数组较大时一般要写在主函数外
int main()
{
	int i;
	a[0]=a[1]=a[2]=1;
	for(i=3;i<20190324;i++)   {
		a[i]=a[i-1]+a[i-2]+a[i-3];
		a[i]%=10000; // 没有这句的话数据太大,因为只需求最后4位数字所以可以每次求完一个就取余		
	}
	cout<<a[20190323]%10000<<endl;
	return 0;
}

Questions D: Decomposition of the number of

The title score: 10.
[Description] Problems
to 2019 decomposed into three different and positive integers, and does not require that each packet positive integer
containing the number 2 and 4, many different methods of decomposing a total of?
Note that the order of switching an integer of 3 is considered the same method, for example, 1000 + 1001 + 18 and
1001 + 18 + 1000 is regarded as the same.
[Answer] submit
this is a result of fill in the blank questions, you only need to calculate and submit the results. The results of this question is an
integer, when submitting answers to fill in only the integer, fill in the extra content will not score.

Answer: 40785 

#include <iostream>
using namespace std;
bool f(int n) 
{
	int t;
	while(n!=0) {
		t=n%10; // 先判断最后一位数(这里要加个变量t,没有则会让n改变,后面无法判断)
		if(t!=2&&t!=4) n/=10;
		else break;	 
	}
	if(n==0) return 1;
	else return 0;
} 
int main()
{
	int a[2020],i,j=0,k,p=0,ans=0;
    // 要先筛选符合条件的放于数组中,否则不能输出!
	for(i=1;i<2018;i++) {
		if(f(i)) {
			a[j++]=i;
			p++;
		}
	}
	for(i=0;i<p;i++)
	  for(j=i+1;j<p;j++)
	    for(k=j+1;k<p;k++) {
	   	  if(((a[i]!=a[j])&&(a[i]!=a[k])&&(a[j]!=a[k]))&&((a[i]+a[j]+a[k])==2019)) ans++;
	    }
	cout<<ans<<endl;	
	return 0;
}

I did not think the division can directly access ...

Questions F: special numbers and

Time limit: 1.0s memory limit: 256.0MB out this question: 15 minutes
[Problem Description]
Xiaoming digital 2,0,1,9 digit pair comprising interesting (not including the leading 0), 1 to
such 40 the count includes 1,2,9,10 to 32, 39 and 40, a total of 28, and they are 574.
Will the 1 to n, all such numbers and how much?
[Input format
input line contains two integers n.
[] Output format
output line, comprising an integer, and represents a number satisfying the condition.
[Sample input]
40
[output] Sample
574
[Evaluation] and conventions used in Example scale
for evaluation with 20% cases, 1≤n≤10.
For 50% Reviews embodiment, 1≤n≤100 use.
For 80% Reviews embodiment, 1≤n≤1000 use.
For reviews all cases, 1≤n≤10000 use.

#include <iostream>
using namespace std;
bool f(int n) 
{
	int t;
	while(n) {
		t=n%10; // 先判断最后一位数(这里要加个变量t,没有则会让n改变,后面无法判断)
		if(t==2||t==0||t==1||t==9) {
			return 1; continue;
		}
		n/=10; 
	}
	if(n==0) return 0;
} 
int main()
{
	int i,n,ans=0;  cin>>n;
	for(i=1;i<=n;i++) {
		if(f(i)) ans+=i;		
	}
	cout<<ans<<endl;		
	return 0;
}

Questions H: arithmetic sequence

Time limit: 1.0s Memory Limit: 256.0MB this question score: 20 points
[Problem Description]
math teacher gave Xiaoming out of an arithmetic sequence summation problem. However, careless Xiaoming forget a
number of column portions, just remember where N is an integer.
This now gives N integers, Xiao Ming wanted to know the shortest contain integer arithmetic of the N series have
several?
[Input format
of the first line of the input contains an integer N.
The second line contains N integers A1, A2, ···, AN. (Note that not necessarily to A1 ~AN arithmetic
order given column)
[] output format
output represents an integer answer.
[Sample input]
. 5
2.64102 million
[output] Sample
10
[] Example Description
containing 2,6,4,10,20 shortest arithmetic sequence is 2,4,6,8,10,12,14,16 ,
18, 20.
[Evaluation] patients with the scale and agreed
to review all use cases, 2≤N≤100000

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

int a[100001];
int main()
{
	int n,i,ans; cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	sort(a,a+n); 头文件为 #include <algorithm>
	int d=a[1]-a[0],max=a[0],min=a[0]; // d为公差
	
	for(i=1;i<n-1;i++) {
		if(a[i+1]-a[i]<d) d=a[i+1]-a[i];	
	}
	for(i=1;i<n;i++) {
		if(a[i]>max) max=a[i];
		if(a[i]<min) min=a[i];
	}
	cout<<(max-min)/d+1<<endl;
		
	return 0;
}

Summary: When thinking is an in-depth process, as has been found can not make the time to try to change kinds of ideas, start from scratch.

 

Guess you like

Origin blog.csdn.net/qq_42458302/article/details/89343973