The second game of the 11th Blue Bridge Cup Group B provincial competition (fill in the blanks)

A

Dismantle directly and count.

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int ans=0;
	for(int i=2;i<=2020;i++){
    
    
		int n=i;
		while(n){
    
    
			if(n%10==2) ans++;
			n/=10;
		}
	}
	cout<<ans;
	return 0;
} 

B

gcd(i,j)==1 means that i and j are relatively prime, which is the reduced score mentioned in the title, using i as a component and j as a component, and violent counting is enough.

#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    
    
	int a=max(x,y);
	int b=min(x,y);
	int temp;
	while(a%b){
    
    
		temp=a;
		a=b;
		b=temp%b;
	}
	return b;
}
bool judge(int x,int y){
    
    
	if(gcd(x,y)==1) return 1;
	return 0;
} 
int main(){
    
    
	int ans=0;
	for(int i=1;i<=2020;i++){
    
    
		for(int j=1;j<=2020;j++){
    
    
			if(judge(i,j)) ans++;
		}
	}
	cout<<ans;
	return 0;
} 

C

Snake-shaped fill in the numbers, simulation questions.

#include<bits/stdc++.h>
using namespace std;
int a[100][100];
int dir[4][2]={
    
    	
	{
    
    -1,1},{
    
    0,1},{
    
    1,-1},{
    
    1,0}
};
bool judge(int x,int y){
    
    
	if(x>=1&&y>=1) return 1;
	return 0;
}
int main(){
    
    
	int cnt=1;
	int p=1;
	int i=1,j=1;
	a[i][j]=cnt++;
	while(p<=40){
    
    
		//a[i][j]=cnt++;
		//cout<<i<<" "<<j<<endl;
		j+=1;
		a[i][j]=cnt++;
		//cout<<i<<" "<<j<<endl;
		while(j!=1&&judge(i,j)){
    
    
			j-=1;
			i+=1;
			a[i][j]=cnt++;
			//cout<<i<<" "<<j<<endl;
		}
		i+=1;
		a[i][j]=cnt++;
		//cout<<i<<" "<<j<<endl;
		while(i!=1&&judge(i,j)){
    
    
			j+=1;
			i-=1;
			a[i][j]=cnt++;
			//cout<<i<<" "<<j<<endl;
		}
		p++;
	}
	for(int i=1;i<=20;i++){
    
    
		for(int j=1;j<=20;j++){
    
    
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<a[20][20];
	return 0;
}

D

I was in trouble, anyway, I was offline, so I made more judgments and compared the ink when dealing with the days in February. It is also a mock question.
Use a variable to record the number of days, and a variable to record the day of the week, and then update it by segment.

#include<bits/stdc++.h>
using namespace std;
int m[13]={
    
    0,31,28,31,30,31,30,31,31,30,31,30,31};
int ml[13]={
    
    0,31,29,31,30,31,30,31,31,30,31,30,31};
int main(){
    
    
	long long ans=0;
	int d=1;
	int mm=1;
	int ye=2000;
	int f=6;
	int temp=0;
	while(!(ye==2020&&mm==10&&d==2)){
    
    
		ans++;
		if(d==1||f==1) ans++;
		d++;
		f++;
		if(f>7) f=1;
		if(temp){
    
    
			if(d>ml[mm]){
    
    
				d=1;
				mm++;
			}
		}else{
    
    
			if(d>m[mm]){
    
    
				d=1;
				mm++;
			}
		}
		if(mm>12){
    
    
			mm=1;
			ye++;
		}
		if(ye==2000||ye==2004||ye==2008||ye==2012||ye==2016||ye==2020){
    
    
			temp=1;
		}else{
    
    
			temp=0;
		}
		//cout<<ye<<" "<<mm<<" "<<d<<endl;
	}
	cout<<ans;
	return 0;
}

E

It's a bit uncomfortable. (Looking at the code of the
boss ) Why do we need dfs, because the title says that the light-emitting diode should be continuous.
How to construct a continuum, looking at the 8, we find that a is connected to f and b, f is connected to g, e, and so on.
Then use the array to save, you will find a problem, that is, b can go to c, and g can go to c. If it is suitable for direct search, we use a # to supplement this position, which means that this is a road that has no letters but can be passed. When searching for elements, you can judge #, and then splice.
The rest is nothing, enumerate each position, then search, sort first, and then use set to duplicate it.
Insert picture description here
Insert picture description here

#include<bits/stdc++.h>
using namespace std;
char str[8][8]={
    
    
	{
    
    'a','b','#'},{
    
    'f','g','c'},{
    
    '#','e','d'}
};
int dir[4][2]={
    
    
	{
    
    -1,0},{
    
    0,-1},{
    
    1,0},{
    
    0,1}
};
int vis[8][8];
set<string> se;
string qsort(string s){
    
    
	char p[10];
	memset(p,'#',sizeof(p));
	int n=0;
	int len=s.size();
	for(int i=0;i<len;i++){
    
    
		if(s[i]!='#'){
    
    
			p[n++]=s[i];
		}
	}
	sort(p,p+n);
	string qq;
	for(int i=0;i<n;i++){
    
    
		qq+=p[i];
	}
	return qq;
}
bool judge(int x,int y){
    
    
	if(x>=0&&y>=0&&x<3&&y<3&&!vis[x][y]) return 1;
	return 0;
}
void dfs(int x,int y,string t){
    
    
	vis[x][y]=1;
	for(int i=0;i<4;i++){
    
    
		int xx=x+dir[i][0];
		int yy=y+dir[i][1];
		if(judge(xx,yy)){
    
    
			string tem=qsort(t+str[xx][yy]);
			se.insert(tem);
			vis[xx][yy]=1;
			dfs(xx,yy,tem);
			vis[xx][yy]=0;
		}
	}
	return ;
}
int main(){
    
    
	for(int i=0;i<3;i++){
    
    
		for(int j=0;j<3;j++){
    
    
			if(str[i][j]!='#'){
    
    
				string s;
				s+=str[i][j];
				string q=qsort(s);
				se.insert(q);
				memset(vis,0,sizeof(vis));
				dfs(i,j,q);
			}
		}
	}
	cout<<se.size();
	return 0;
}

Answer:
(1) 624
(2) 2481215
(3) 761
(4) 8879
(5) 80


Supplement after the program questions.

Guess you like

Origin blog.csdn.net/iuk11/article/details/114109594