The first individual problem solution of the 13th Lanqiao Cup Provincial Competition (2022)

Test Question A: Convert Nine to Decimal (5 points)

Insert image description here
Answer:

1478

Code:

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	long long  ans = 2*1+2*9+0*pow(9,2)+2*pow(9,3);
	cout<<ans; 
	return 0;
} 

Question B: Straight Date (5 points)

[Problem Description]
Xiao Ming particularly likes Shunzi. A straight refers to three consecutive numbers: 123, 456, etc. The straight date refers to the yyyymmdd representation of the date.Any consecutive three digits is a straight date. For example, 20220123 is a straight date.Because it came out as a straight: 123;And 20221023 is not a straight date, it does not have a straight date. Xiao Ming wants to know how many straight dates there are in the entire 2022 year.
[Answer submission]
This is a fill-in-the-blank question. You only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. No points will be awarded if you fill in extra content.

Thoughts: One drawback of this question is, does 012 count as a straight?

Answer (count as zero):

14

Does not count:

4

Code 1: (0 counts)

#include<bits/stdc++.h>
using namespace std;
int dt[15] = {
    
    0,31,28,31,30,31,30,31,31,30,31,30,31};
int f[5];
bool check(){
    
    
	for(int i = 2; i <=3;i++){
    
    
		if(f[i-1]+1==f[i]&&f[i]+1==f[i+1]) return true;
	}
	return false;
}
int main(){
    
    
	int ans = 0;
	for(int i = 1; i<= 12;i++){
    
    
		for(int j = 1; j <= 31;j++){
    
    
			f[1]= 0,f[2]=0,f[3]=0,f[4]=0;
			if(j<=dt[i]){
    
    
				if(i>=10){
    
    
					f[1] = i/10; f[2] = i%10;
				}else f[2] = i%10;
				
				if(j>=10){
    
    
					f[3] = j/10; f[4] = j%10;
				}else f[4] = j%10; 
				if(check()) ans++;
			}
		}
	}
	cout<<ans;
	return 0;
} 

Code (not counting 0):

#include<bits/stdc++.h>
using namespace std;
int dt[15] = {
    
    0,31,28,31,30,31,30,31,31,30,31,30,31};
int f[5];
bool check(){
    
    
	for(int i = 2; i <=3;i++){
    
    
		if(f[i-1]+1==f[i]&&f[i]+1==f[i+1]&&f[i-1]&&f[i]&&f[i+1]) return true;
	}
	return false;
}
int main(){
    
    
	int ans = 0;
	for(int i = 1; i<= 12;i++){
    
    
		for(int j = 1; j <= 31;j++){
    
    
			f[1]= 0,f[2]=0,f[3]=0,f[4]=0;
			if(j<=dt[i]){
    
    
				if(i>=10){
    
    
					f[1] = i/10; f[2] = i%10;
				}else f[2] = i%10;
				
				if(j>=10){
    
    
					f[3] = j/10; f[4] = j%10;
				}else f[4] = j%10; 
				if(check()) ans++;
			}
		}
	}
	cout<<ans;
	return 0;
} 

Question C: Statistics (10 points)

Insert image description here
Input example:

10 20 99

Output sample:

8

Insert image description here
Thoughts: What I was thinking was to write about violence first and then work it out week by week? Compress the loop and
there will be no time.

Code: (It is estimated that the water will not be exhausted)

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	long long a,b,n;
	cin>>a>>b>>n;
	long long sum = 0,cnt = 0;
	while(sum<n){
    
    
		for(int i = 1; i <= 7;i++){
    
    
			if(i>5) sum += b,cnt++;
			else sum += a,cnt++;
			if(sum>=n){
    
    
				cout<<cnt;
				return 0;
			}
		}
	}
	
	return 0;
}

Question D: Pruning Shrubs (10 points)

Insert image description here
Input example:

3

Output sample:

4
2
4

Insert image description here
Code: (This question should not time out)

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int n;
	cin>>n;
	for(int i = 1;i<=n;i++){
    
    
		int ans  = 2*max(i-1,n-i);
		cout<<ans<<endl;
	}
	return 0;
}

Test question E: X base subtraction (15 points) dfs is out! Long live

[Problem Description]
The base system specifies how many digits in a number should be advanced by one.
The X base is a very magical base system because the base of each digit is not fixed! For example, for a certain X-base number, the lowest digit is binary, the second digit is decimal, and the third digit is octal, then the X-base number 321 is converted into a decimal number of 65.
Now there are two integers A and B expressed in base Binary. Please calculate the minimum possible result of AAB.
Please note,you need toEnsure that both A and B are legal in the X base system, that is, the number on each digit must be smaller than its base system.
[Input format]
The first line is a positive integer N, the meaning is as stated in the title.
The second line contains a positive integer Ma, representing the number of digits in the X base number A.
The third line contains Ma integers separated by spaces, which represent the
decimal representation of the numbers on each digit of the X-base number A in order from high to low.
The fourth line contains a positive integer Mb, which represents the number of digits in the X base number B.
The fifth line contains Mb integers separated by spaces, representing the
decimal representation of the numbers on each digit of the X base number B in order from high to low.
Note that all numbers in the input are in decimal.
[Output format]
Output one integer per line, representing the smallest possible value of the result of the X base number AB
after conversion to decimalThen model the result of 1000000007.
Insert image description here

Input example:

11
3
10 4 0
3
1 2 0

Output sample:

94

Thoughts:
I feel this question is so disgusting now! Oh my god, it took almost two hours to write and debug it. Oh my god,
finally the dfs came out, wow, it’s great, but it seems like there was no mold taken and sent.

Code:

#include<bits/stdc++.h>
using namespace std;
int n,ma,mb,ans = 99999999;
int a[100005];
int b[100005];
void dfs(int x,int y,int sa,int sb,int sum){
    
    //两个数位  权值ji
	if(x==ma&&y==mb){
    
    
		ans = min(ans,sa-sb);
		return;
	}else{
    
    
		for(int i = 2; i <=n;i++){
    
     //n是最大倍数
		 
 			if(a[x]>=i||b[x]>=i) continue;  //剪枝 
 			
 			sum *= i;
			sa += a[x+1]*sum; sb += b[y+1]*sum;
			dfs(x+1,y+1,sa,sb,sum);
			
			sa -= a[x+1]*sum; sb -= b[y+1]*sum;
			sum /= i;
		}
	}
}
int main(){
    
    
	cin>>n;
	cin>>ma;
	for(int i = ma; i >=1;i--) cin>>a[i];
	cin>>mb;
	for(int i = mb; i >= 1;i--) cin>>b[i];
	dfs(1,1,a[1],b[1],1);
	cout<<ans;
	return 0;
}

It's not easy to take the model when searching. I don't want to adjust it. I guess it won't work.

#include<bits/stdc++.h>
using namespace std;
int n,ma,mb;
int a[100005];
int b[100005];
typedef long long ll;
const ll mod = 1000000007;
ll ans = 99999999;

void dfs(int x,int y,ll sa,ll sb,ll sum){
    
    //两个数位  权值ji
	if(x==ma&&y==mb){
    
    
		ans = min(ans,(sa%mod-sb%mod)%mod);
		//cout<<"................."<<endl;
		//cout<<"xy: "<<x<<" "<<y<<" "<<" he: "<<sa<<" "<<sb<<" ans: "<<ans<<endl;
		return;
	}else{
    
    
		for(int i = 2; i <=n;i++){
    
     //n是最大倍数
		 
 			if(a[x]>=i||b[x]>=i) continue;  //剪枝 
			//cout<<"be: "<<i<<" xy: "<<x<<" "<<y<<" he: "<<sa<<" "<<sb<<" ji: "<<sum<<" "<<ans<<endl; 
 			sum *= i;
			sa += a[x+1]*sum; sb += b[y+1]*sum;
			dfs(x+1,y+1,sa,sb,sum);
			sa -= a[x+1]*sum; sb -= b[y+1]*sum;
			sum /= i;
		}
	}
}
int main(){
    
    
	cin>>n;
	cin>>ma;
	for(int i = ma; i >=1;i--) cin>>a[i];
	cin>>mb;
	for(int i = mb; i >= 1;i--) cin>>b[i];
	dfs(1,1,a[1],b[1],1);
	cout<<ans;
	return 0;
}

Question F: Statistical submatrices (15 points)

Insert image description here
Input example:

3 4 10
1 2 3 4
5 6 7 8
9 10 11 12

Output sample:

19

[Example description]
There are 19 submatrices that meet the conditions, including:
10 with a size of 1 × 1.
There are 3 of the size 1 × 2.
There are 2 of the size 1 × 3.
There is 1 size 1 × 4.
There are 3 of size 2 × 1.
Insert image description here
Thoughts: Direct two-dimensional prefix and but I seem to have written it wrong

Guess you like

Origin blog.csdn.net/qq_52626583/article/details/124103572