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

试题 A: 组队

答案:490

试题 B: 年号字串

#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: 数列求值

#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: 数的分解

#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: 迷宫

#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: 特别数的和

相关推荐

  1. 大学B填空(c++)

    2024-04-12 10:36:03       41 阅读
  2. 大学B(C/C++)整数删除

    2024-04-12 10:36:03       48 阅读
  3. 冶炼金属 二分法 B

    2024-04-12 10:36:03       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-12 10:36:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-12 10:36:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-12 10:36:03       82 阅读
  4. Python语言-面向对象

    2024-04-12 10:36:03       91 阅读

热门阅读

  1. ORACLE查看数据库中用户,用户创建修改

    2024-04-12 10:36:03       123 阅读
  2. 力扣爆刷第117天之CodeTop100五连刷71-75

    2024-04-12 10:36:03       31 阅读
  3. ChatGPT 写作利器:探索ChatGPT在论文写作中的应用

    2024-04-12 10:36:03       41 阅读
  4. Transformer介绍

    2024-04-12 10:36:03       41 阅读
  5. PHP学习

    PHP学习

    2024-04-12 10:36:03      147 阅读
  6. 计算机网络2

    2024-04-12 10:36:03       30 阅读
  7. (二)PostgreSQL常用的配置文件

    2024-04-12 10:36:03       86 阅读
  8. 深度学习笔记

    2024-04-12 10:36:03       34 阅读
  9. oracle逻辑读详解

    2024-04-12 10:36:03       44 阅读