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

2021蓝桥杯国赛c++B组

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

2021蓝桥杯国赛c++B组

先推荐两个好用的备赛网站:
1)c语言网
2)new oj

//带宽 
#include
using namespace std;
int main()
{
	cout<<200/8;
	
	return 0; 
}

//纯素数
//模拟
//答案:1903
#include
using namespace std;
const int N=20210610;
int f[N];
void init()//0是素数,1是非素数 
{
	f[0]=1,f[1]=1; 
	for(int i=2;i
		if(f[i]==0)//只需枚举素数,非素数已经被前面的素数标记 
		{
			for(int j=2;j*i
				f[j*i]=1;//标记后面的非素数 
			}
		}	
	}
}
//若每一位都为素数,返回true ; 否则,返回false 
int check(int x)
{
	while(x)
	{
		if(f[x%10]) return false;//非素数 
		x/=10;
	}
	return true;
}
int main()
{
	init();
	int n=20210605;
	int res=0;
	for(int i=1;i<=n;i++)
	{
		if(f[i]==0)//整数i为素数 
		{
			if(check(i)) res++;//每一位都是素数 
		}
	}
	cout< 

//完全日期
//模拟 
//答案:1903
#include
using namespace std;
int nian,yue,ri;
int cnt;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int check(int x)
{
	if(x%400==0||(x%4==0&&x%100!=0)) return true;
	return false;
}
int solve(int nian,int yue,int ri)
{
	int res=0;
	while(nian)
	{
		res+=nian%10;
		nian/=10;
	}
	while(yue)
	{
		res+=yue%10;
		yue/=10;
	}
	while(ri)
	{
		res+=ri%10;
		ri/=10;
	}
	if((int)sqrt(res)*(int)sqrt(res)==res) return true;
	return false;
}

int main()
{
	for(int nian=2001;nian<=2021;nian++)
	{
		if(check(nian)) days[2]=29;
		else days[2]=28;
		for(int yue=1;yue<=12;yue++)
		{
			for(int ri=1;ri<=days[yue];ri++)
			{
				//nian,yue,ri
				if(solve(nian,yue,ri)) cnt++;
			}
		}
	}
	cout< 

//最大权值
//DP
//答案:2653631372
#include
using namespace std;
long long f[2022];//以i为根节点的子树的最小权值 
int main()
{
	memset(f,0x3f,sizeof f);
	f[0]=0;//空子树的权值为0 
	for(int i=1;i<=2021;i++)//以i为结点 ,根节点算1结点 
	{
		for(int j=0;j
			f[i]=min(f[i],1+2*f[j]+3*f[i-j-1]+j*j*(i-j-1));
		}
	}
	cout< 

//大写
//模拟(唯一不水数据的大题) 
#include
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i
		if(s[i]>='a'&&s[i]<='z') s[i]-=32;
	}
	cout< 

//123
//前缀和水数据 
#include
using namespace std;
const int N=1e8+10;
int cnt;
long long w[N];
long long s[N];
int main()
{
	int T;
	cin>>T;
	int group=1,cnt=1;
	for(int i=1;i<=N;i++)//数 
	{
		if(cnt
			w[i]=cnt;
			cnt++;
		}
		else if(cnt==group)
		{
			w[i]=cnt;
			cnt=1;
			group++;
		}
	}
	for(int i=1;i<=N;i++)
	{
		s[i]=s[i-1]+w[i];
	}
	for(int i=0;i
		int l,r;
		cin>>l>>r;
		cout< 

//异或变换
//模拟水数据 
#include
using namespace std;
int n,t;
string s;
int main()
{
	cin>>n>>t;
	cin>>s;
	for(int i=0;i
		for(int j=1;j
			int q=s[i-1]-'0';
			int p=s[i]-'0';
			int t=q^p;
			s[i]=t+'0';
		}
	}
	cout< 

//二进制问题
//二进制水数据 
#include
using namespace std;
int n,k;
int check(int x)
{
	int cnt=0;
	while(x)
	{
		int t=x&1;
		if(t) cnt++;
		x>>=1;
	}
	if(cnt==k) return true;
	return false;
}
int main()
{
	cin>>n>>k;
	int res=0;
	for(int i=1;i<=n;i++)
	{
		if(check(i)) res++;
	}
	cout< 

//翻转括号序列
//模拟水数据 
#include
using namespace std;
int n,m;
string s;
int main()
{
	cin>>n>>m>>s;
	for(int i=0;i
		int op,l=0,r=0;
		cin>>op;
		if(op==1)
		{
			cin>>l>>r;
			for(int j=l-1;j<=r-1;j++)
			{
				if(s[j]=='(') s[j]=')';
				else s[j]='(';
			}
		}
		else
		{
			cin>>l;
			int lef=0,rig=0;
			for(int j=l-1;j	
				if(s[j]=='(') lef++;//左括号 
				if(s[j]==')') rig++;//右括号 
				if(lef==rig) r=j;//配对,更新右端点 
				if(lef < rig) break;//左括号小于右括号,不合法 
			}
			if(r) cout< 

//异或三角 
//三重循环水数据 
#include
using namespace std;
int T,n;
long long ans;
int check(int a,int b,int c)
{
	int t=((a^b)^c);
	if(t) return false;//异或不满足 
	//异或满足 ↓ 
	if(abs(a-b)
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				for(int k=1;k<=n;k++)
				{
					if(check(i,j,k)) ans++;
				}
			}
		}
		cout<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/864414.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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