第十届蓝桥杯省赛真题(C/C++大学B组)

试题 A: 组队

答案:490

试题 B: 年号字串

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main()
{
	//26进制数 
	int n;
	cin>>n;
	string s = "111";
	for(int i = s.length() - 1;i >=0;i--)
	{
		s[i] = 'A' - 1 + n % 26;
		n /= 26;
	}
	cout<<s<<endl;
	
	return 0;
}

试题 C: 数列求值

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int a1=1,a2=1,a3=1,ans=0;

	for(int i = 4;i <= 20190324;i++)
	{
		ans = (a3 + a2 + a1) % 10000;
		a1 = a2;
		a2 = a3;
		a3 = ans;
	}
	cout<<ans<<endl;
	
	return 0;
}

试题 D: 数的分解

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

bool judge(int n)
{
	int t;
	while(n > 0)
	{
		t = n % 10;
		if(t == 2 || t == 4) return false;
		n /= 10;
	}
	return true;
}

int main()
{
	int ans = 0;
	for(int a = 1;a < 2019;a++)
	{
		if(!judge(a)) continue;
		for(int b = a + 1;b < 2019 - a - b;b++)
		{
			if(judge(b) && judge(2019 - a - b))  ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

试题 E: 迷宫

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int mapp[502][502],vis[502][502],n,m,maxn;
int dir[4][2]={1,0,0,-1,0,1,-1,0};
char di[4]={'D','L','R','U'};
string str1;
struct node{
	int x,y,num;
	string str;
};
void bfs(int x,int y,string str,int num)
{
	queue<node> que;
	node aa;
	aa.x=x;
	aa.y=y;
	aa.str=str;
	aa.num=num;
	que.push(aa);
     vis[1][1]=1;
	while(!que.empty())
	{
		
		node no=que.front();
		que.pop();
		//cout<<no.x<<" "<<no.y<<" "<<no.num<<" "<<no.str<<endl;
		if(no.x==n&&no.y==m)
		 {
		 	maxn=no.num;
		 	str1=no.str;
		 	break;
		 }
		
		for(int i=0;i<4;i++)
		{
		   	int xx=dir[i][0]+no.x;
   	        int yy=dir[i][1]+no.y;
   	        if(xx<=n&&xx>=1&&yy<=m&&yy>=1)
   	        if(!mapp[xx][yy])
   	        if(!vis[xx][yy])
   	        {
   	        	vis[xx][yy]=1;
				no.str.push_back(di[i]);
   	        	node a;
   	        	a.x=xx;
   	        	a.y=yy;
   	        	a.str=no.str;
   	        	a.num=no.num+1;
   	        //	cout<<a.x<<" "<<a.y<<" "<<a.num<<" "<<a.str<<endl;
   	        	que.push(a);
   	        	no.str.erase(no.str.size()-1);
			   }
		}
	}
}

int main()
{
	cin>>n>>m;
	string str;
	for(int i=1;i<=n;i++)
  {
  char c;
  c=getchar();
   for(int j=1;j<=m;j++)
    {
    	c=getchar();
        mapp[i][j]=c-'0';	
	}
    
	} 
    maxn=99999999;
    
    bfs(1,1,str,0);
    cout<<maxn<<endl<<str1;
	return 0;
 }

试题 F: 特别数的和

相关推荐
让我们一起加油好吗5 小时前
【基础算法】初识搜索:递归型枚举与回溯剪枝
c++·算法·剪枝·回溯·洛谷·搜索
郝学胜-神的一滴5 小时前
Horse3D游戏引擎研发笔记(七):在QtOpenGL环境下,使用改进的Uniform变量管理方式绘制多彩四边形
c++·3d·unity·游戏引擎·图形渲染·虚幻·unreal engine
2401_876221347 小时前
Reachability Query(Union-Find)
c++·算法
tju新生代魔迷8 小时前
C语言宏的实现作业
c语言·开发语言
小莞尔9 小时前
【51单片机】【protues仿真】基于51单片机宠物投食器系统
c语言·stm32·单片机·嵌入式硬件·51单片机·proteus
躲着人群9 小时前
次短路&&P2865 [USACO06NOV] Roadblocks G题解
c语言·数据结构·c++·算法·dijkstra·次短路
一只鲲10 小时前
56 C++ 现代C++编程艺术5-万能引用
开发语言·c++
小欣加油11 小时前
leetcode 1493 删掉一个元素以后全为1的最长子数组
c++·算法·leetcode
争不过朝夕,又念着往昔11 小时前
即时通讯项目---网关服务
linux·c++·vscode
蓝风破云12 小时前
C++实现常见的排序算法
数据结构·c++·算法·排序算法·visual studio