第九届蓝桥杯国赛b组--备战国赛版h

第一题:0换零钞 - 蓝桥云课

模拟

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c=0;
  for(a=1;a<200;a++)//一元钞票
  {
    for(b=1;b<100;b++)//两元钞票
    {
      for(c=1;c<40;c++)//五元钞票
      {
        if(b==a*10&&(a+b*2+c*5)==200)
        {
          cout<<a+b+c<<endl;
          return 0;
        }
      }
    }
  }
  return 0;
}

第二题:0激光样式 - 蓝桥云课

dfs枚举然后填空

cpp 复制代码
#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  cout<<2178309<<endl;
  return 0;
}
/*
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=30;
int ans=0;

void dfs(int x,int last)
{
	if(x>30)
	{
		ans++;
		return;
	}
	dfs(x+1,last);
	if(last!=x-1||last==0)
	{
		dfs(x+1,x);
	}
} 

int main()
{
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
} 
*/

第三题:0格雷码 - 蓝桥云课

填空题是没想到的

第四题:0调手表 - 蓝桥云课

用bfs

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=100010;
int n,k;
int dist[N];

int main()
{
	cin>>n>>k;
	memset(dist,-1,sizeof dist);
	
	queue<int> q;
	dist[0]=0;
	q.push(0);
	
	while(q.size())
	{
		int u=q.front();
		q.pop();
		int v1=(u+1)%n;
		if(dist[v1]==-1)
		{
			dist[v1]=dist[u]+1;
			q.push(v1);
		}
		int v2=(u+k)%n;
		if(dist[v2]==-1)
		{
			dist[v2]=dist[u]+1;
			q.push(v2);
		}
	}
	
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans=max(ans,dist[i]);
	}
	cout<<ans<<endl;
	return 0;
} 

第五题:0搭积木 - 蓝桥云课

想着是用dfs解决,但是没有解决出来

第六题:0矩阵求和 - 蓝桥云课​​​​​​

直接模拟--》拿到了10分

cpp 复制代码
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1010,MOD=1e9+7;

int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
} 

int g[N][N];
int n;
long long sum=0;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int x=gcd(i,j);
			g[i][j]=x*x; 
			sum=(sum+g[i][j])%MOD;
		}
	}
	cout<<sum<<endl;
	return 0;
	
}
相关推荐
WL_Aurora1 天前
备战蓝桥杯国赛【Day 18】
python·算法·蓝桥杯
210Brian1 天前
蓝桥杯单片机学习笔记(十二):V2026 大模板构建(上)
单片机·学习·蓝桥杯
WL_Aurora2 天前
备战蓝桥杯国赛【Day 17】
算法·蓝桥杯
此生决int3 天前
算法从入门到精通——滑动窗口
c++·算法·蓝桥杯
WL_Aurora3 天前
备战蓝桥杯国赛【Day 16】
python·蓝桥杯
奔跑的Ma~3 天前
第6篇:蓝桥杯C++进阶突破(难题拆解+算法优化,冲刺国赛高奖)
c++·算法·蓝桥杯·#蓝桥杯备战·#c++编程·编程竞赛
x_yeyue4 天前
2026第十七届蓝桥杯c++B组省赛题解
笔记·算法·蓝桥杯·acm·题解
handler014 天前
【C++ 算法竞赛基础】数论篇:核心公式、经典例题与高频模板
开发语言·c++·算法·蓝桥杯·数论·最大公约数·最小公倍数
WL_Aurora4 天前
备战蓝桥杯国赛【Day 15】
python·蓝桥杯