栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

2021蓝桥杯国赛C/C++B组真题

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021蓝桥杯国赛C/C++B组真题

 

答案:2653631372 

#include
#include
#define ll long long
using namespace std;
ll dp[2022];
int main()
{
    memset(dp,0x7f,sizeof(dp));//初始化最大值;
    dp[0]=0;//根据题意,当子树为空时权值为0;
    //dp[i]代表有i个结点来组成这棵树 
    for(int i=1;i<=2021;i++)//自下而上;
        for(int j=0;j 

【解析】

 

一开始自己写的代码:用的是ASCII码 

#include
#include
#include
using namespace std;

//a~97 A~65 

int main(){
	string myS;
	cin>>myS;
	for(int i=0;i=97)
		myS[i]-=32;
	}
	cout< 

然后发现还有一个toupper() 函数, int toupper(int c) ,用来将小写字母转换为大写字母。 只有当参数 c 是一个小写字母,并且存在对应的大写字母时,这种转换才会发生。

需要#include

#include
#include
#include
#include
using namespace std;

//a~97 A~65 

int main(){
	char c;
	while(cin>>c){
		cout<<(char)toupper(c);
	}
	return 0;
}

 【思路】

 二分代码不太明白,多理解几遍

#include

using namespace std;

typedef long long ll;

//到第n 块 的前缀和 
ll cal1(ll n){
	return n*(n+1)*(n+2)/6;
}

//在某一个从1开始的块中,前n个数的和 
//或者是求从第1个块开始到第n块一个有多少个数 
ll cal2(ll n){
	return n*(n+1)/2;
} 

// 二分 查看第n个数前面有多少个完整的块
ll getSeg(ll n){
	ll l=1,r=1e9,mid,ans;
	while(l<=r){
		mid=l+(r-l)/2;
	    //块数少了,加起来到不了第n个数 
		if(cal2(mid)<=n){
			ans=mid;
			l=mid+1; 
		}
		else r=mid-1;
	}
	return ans;
}
//参数都是代表[第n个数] 
ll solve(ll n){
	if(n==0)return 0;
	ll s=getSeg(n);	//s代表n前面的完整块数 
	return cal2(n-cal2(s))+cal1(s);
}

int main(){
	int T;
	ll l,r;
	cin>>T;
	while(T--){
		cin>>l>>r;
		cout< 

 

 【思路】

显然这是一道经典的数位dp

#include
#include
#include
using namespace std;
typedef long long ll; 

ll dp[105][55];
int limit[105];
int k;

ll dfs(int pos,int sum,int flag){
	if(pos<0) return sum==k;
	if(!flag && dp[pos][sum]!=-1)
		return dp[pos][sum];
	int up=flag?limit[pos]:1;
	ll ans=0;
	for(int i=0;i<=up;i++){
		ans+=dfs(pos-1,sum+(i==1),flag &&(i==up));
	}
	if(!flag) dp[pos][sum]=ans;
	return ans;
}

ll solve(ll n){
	int pos=0;
	while(n){
		limit[pos++]=n&1;
		n/=2;
	}
	memset(dp,-1,sizeof(dp));
	return dfs(pos-1,0,1);
}

int main(){
	ll n;
	cin>>n>>k;
	cout< 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/857111.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号