第九届蓝桥杯国赛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;
	
}
相关推荐
依然鸣3 天前
PTA团体程序设计天梯赛L2真题讲解L2-037-040
c++·经验分享·学习·算法·蓝桥杯·深度优先·pat考试
YuforiaCode4 天前
第十六届蓝桥杯 2025 C/C++组 数列差分
c语言·c++·蓝桥杯
QAQo7T4 天前
Python组蓝桥杯备赛超详细知识点总结笔记_排序算法篇
笔记·python·算法·蓝桥杯·排序算法
普通网友4 天前
蓝桥杯 DP 优化:从 O (n²) 到 O (n) 的滚动数组实战
职场和发展·蓝桥杯
醉颜凉4 天前
蓝桥杯2025年第十六届省赛真题-好串的数目
职场和发展·蓝桥杯
醉颜凉4 天前
蓝桥杯2025年第十六届省赛真题-最大数字 Python题解
python·职场和发展·蓝桥杯
2301_806204464 天前
蓝桥杯第十四届省赛代码参考
职场和发展·蓝桥杯
Ronin-Lotus4 天前
蓝桥杯篇---EEPROM内部存储地址
职场和发展·蓝桥杯·c·eeprom·keil
计算机小白一个4 天前
蓝桥杯 Java B 组之哈希表应用(两数之和、重复元素判断)
java·数据结构·算法·蓝桥杯
依然鸣6 天前
蓝桥杯多校模拟赛 题解
数据结构·c++·经验分享·学习·算法·蓝桥杯