2025年河南省蓝桥杯省赛(c/c++)ABCDEF题解

目录

A:移动距离

B:客流量上限

C:可分解的正整数

D:产值调整

E:画展布置

F:水质检测

A:移动距离

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int x=233,y=666;
void solve(){
	double l=sqrt(x*x+y*y);//斜边长
	double q=atan(y*1.0/x); //以x为半径的弧度
	double res=l+l*q;
	cout<<l<<endl;
	cout<<q<<endl;
	cout<<res<<endl;
} 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

B:客流量上限

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int mod = 1e9+7;
int N =2025;
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
void solve(){
	int tmp=qpow(2,N/2);
	cout<<tmp<<endl; 
} 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

C:可分解的正整数

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 100010;
int a[N];
void solve(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int res=0;
	for(int i=1;i<=n;i++){
		if(a[i]==1) continue;	//只有1不可分解
		res++;
	}
	cout<<res;
} 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}

D:产值调整

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve(){
	int a,b,c,k;
	cin>>a>>b>>c>>k; 
		for(int i=1;i<=k;i++){
			int tmp=a,num=b;
			a=(b+c)/2;
			b=(tmp+c)/2;
			c=(tmp+num)/2;
			if(a==b&&b==c)break;//k循环到一定次数(50--100次),a,b,c就相等了
		}
	cout<<a<<' '<<b<<' '<<c<<endl;
	return ;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}
/*
2
10 20 30 1
5 5 5 3
*/

E:画展布置

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 100010;
int a[N],b[N];
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i]*a[i];
	}
	sort(b+1,b+n+1);
	int l=0,r=0,Min=1e18;//这里要开long long 的最大值,如果开0x3f3f3f(int的最大值)不全对
	for(int i=1;i<=n-m+1;i++){
		int tmp=b[i+m-1]-b[i];
		if(tmp<Min){
			l=i;
			r=i+m-1;
			Min=tmp;
		}
	}
	int res=b[r]-b[l];
	cout<<res<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}
/*
4 2
1 5 2 4
*/

F:水质检测

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 1000010;
char c[2][N];
void solve(){
	string a,b;
	cin>>a>>b;
	int n=a.size();
	for(int i=0;i<n;i++){
		c[0][i+1]=a[i];
		c[1][i+1]=b[i];
	}
	int l,r;	//l第一次出现#的列,r最后一次出现#的列
	for(int i=1;i<=n;i++){
		if(c[0][i]=='#'||c[1][i]=='#'){
			l=i;
			break;
		}
	}
	for(int i=n;i>=1;i--){
		if(c[0][i]=='#'||c[1][i]=='#'){
			r=i;
			break;
		}
	}
	int res=0;
	for(int i=l;i<=r-1;i++){
		if(c[0][i]=='.'&&c[0][i+1]=='#'&&c[1][i]=='#'&&c[1][i+1]=='.'){	
			res++;
			c[1][i+1]='#';
		}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='.'&&c[1][i+1]=='#'){
			res++;
			c[0][i+1]='#';
		}else if(c[0][i]=='.'&&c[0][i+1]=='.'&&c[1][i]=='#'&&c[1][i+1]=='.'){
			res++;
			c[1][i+1]='#';
		}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='.'&&c[1][i+1]=='.'){
			res++;
			c[0][i+1]='#';
		}else if(c[0][i]=='#'&&c[0][i+1]=='.'&&c[1][i]=='#'&&c[1][i+1]=='.'){
			if(i<=n-2){
				int num=-1;
				for(int j=i+1;j<=n;j++){
					if(c[0][j]=='#'){
						num=0;
						break;
					}else if(c[1][j]=='#'){
						num=1;
						break;
					}
				}
				if(num==0){
					res++;
					c[num][i+1]='#';
				}else if(num==1){
					res++;
					c[num][i+1]='#';
				}
			}
			
		}
	}
	cout<<res<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}
/*
.##.....#
.#.#.#...
#..#.........
.....#...##.#
#..#.........
.....#..#....
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值