第十五届蓝桥杯模拟赛(第一期 C++)

1、最小的十六进制

问题描述
  请找到一个大于 2022 的最小数,这个数转换成十六进制之后,所有的数位(不含前导 0)都为字母(A 到 F)。请将这个数的十进制形式作为答案提交。   

答案:2730

思路分析:直接暴力秒了

2、Excel的列

问题描述
  在 Excel 中,列的名称使用英文字母的组合。前 26 列用一个字母,依次为 A 到 Z,接下来 26*26 列使用两个字母的组合,依次为 AA 到 ZZ。请问第 2022 列的名称是什么?

答案:BYT

思路分析:Excel大法 or 暴力循环 or 口算

3、 相等日期

问题描述

        对于一个日期,我们可以计算出年份的各个数位上的数字之和,也可以分别计算月和日的各位数字之和。请问从 1900 年 1 月 1 日至 9999 年 12 月 31 日,总共有多少天,年份的数位数字之和等于月的数位数字之和加日的数位数字之和。
        例如,2022年11月13日满足要求,因为 2+0+2+2=(1+1)+(1+3) 。
        请提交满足条件的日期的总数量。
 

答案:70910

思路分析:暴力大法

4、多少种取法

问题描述
  小蓝有 30 个数,分别为:99, 22, 51, 63, 72, 61, 20, 88, 40, 21, 63, 30, 11, 18, 99, 12, 93, 16, 7, 53, 64, 9, 28, 84, 34, 96, 52, 82, 51, 77 。
  小蓝可以在这些数中取出两个序号不同的数,共有 30*29/2=435 种取法。
  请问这 435 种取法中,有多少种取法取出的两个数的乘积大于等于 2022 。

答案:189

思路分析:还是直接写暴力

5、最大连通分块

问题描述
  小蓝有一个 30 行 60 列的数字矩阵,矩阵中的每个数都是 0 或 1 。
  110010000011111110101001001001101010111011011011101001111110
  010000000001010001101100000010010110001111100010101100011110
  001011101000100011111111111010000010010101010111001000010100
  101100001101011101101011011001000110111111010000000110110000
  010101100100010000111000100111100110001110111101010011001011
  010011011010011110111101111001001001010111110001101000100011
  101001011000110100001101011000000110110110100100110111101011
  101111000000101000111001100010110000100110001001000101011001
  001110111010001011110000001111100001010101001110011010101110
  001010101000110001011111001010111111100110000011011111101010
  011111100011001110100101001011110011000101011000100111001011
  011010001101011110011011111010111110010100101000110111010110
  001110000111100100101110001011101010001100010111110111011011
  111100001000001100010110101100111001001111100100110000001101
  001110010000000111011110000011000010101000111000000110101101
  100100011101011111001101001010011111110010111101000010000111
  110010100110101100001101111101010011000110101100000110001010
  110101101100001110000100010001001010100010110100100001000011
  100100000100001101010101001101000101101000000101111110001010
  101101011010101000111110110000110100000010011111111100110010
  101111000100000100011000010001011111001010010001010110001010
  001010001110101010000100010011101001010101101101010111100101
  001111110000101100010111111100000100101010000001011101100001
  101011110010000010010110000100001010011111100011011000110010
  011110010100011101100101111101000001011100001011010001110011
  000101000101000010010010110111000010101111001101100110011100
  100011100110011111000110011001111100001110110111001001000111
  111011000110001000110111011001011110010010010110101000011111
  011110011110110110011011001011010000100100101010110000010011
  010011110011100101010101111010001001001111101111101110011101
  如果从一个标为 1 的位置可以通过上下左右走到另一个标为 1 的位置,则称两个位置连通。与某一个标为 1 的位置连通的所有位置(包括自己)组成一个连通分块。
  请问矩阵中最大的连通分块有多大?

答案:148

思路分析:我觉得直接算比写程序快,我就直接算的

贴个后续写的程序,直接写一个bfs应该是能行的

#include <iostream>
#include <algorihthm>
#include <cstring>
#include <queue>
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;

const int N=35;
const int M=65;

char map[N][M];
bool vis[N][M];

#define fi first
#define se second

#define f(i,a,b) for(int i=a;i<=b;i++)

int dx[4]={1, 0, -1, 0};
int dy[4]={0, 1, 0, -1};

void judge(int x,int y){
	if(x<1||x>30||y<1||y>30) return 1;
	return 0;
}

int bfs(int i,int j){
	int ans=1;//每一步至少都有1个单位的连通块
	
	vis[i][j]=1;//标记为已经来过 
	
	queue<PII> q;//定义一个队列是为了后续好操作
	q.push({i,j});//将当前点放入队列 
	while(q.size()) {
		auto tmp=q.front();
		q.pop();
		f(i,0,3){
			int tox=dx[i]+tmp.fi;
			int toy=dy[i]+tmp.se;
			if(judge(tox,toy)) continue;
		}
	}
	 
	return ans;
}

int main(){
	//初始化
	memset(vis, 0, sizeof vis);
	f(i,1,30){
		f(j,1,60){
			cin>>map[i][j];
		}
	}
	
	//寻找最大连通块 
	int res=0;
	f(i,1,30){
		f(j,1,60){
			if(!vis[i]&&map[i][j]=='1'){
				res=max(res,bfs(i,j));
			}
		}
	}
	
	//输出结果
	cout<<res<<endl; 
	
	return 0;
}

6、哪一天

#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int answer = (a + b % 7) % 7;
    if (answer == 0) {
        cout << 7 << endl;
    } else {
        cout << answer << endl;
    }
}

7、信号覆盖

#include<iostream>
using namespace std;

constexpr auto N = 110;
#define f(i,a,b) for(int i=a;i<=b;i++)
int w, h, n, r;

bool range[N][N];

int main(){
    int num = 0;

    scanf_s("%d %d %d %d", &w, &h, &n, &r);

    while (n--){
        int x, y, left, right, up, down;
        scanf_s("%d %d", &x, &y);
        left = (x - r < 0 ? 0 : x - r);
        right = (x + r > w ? w : x + r);
        up = (y + r > h ? h : y + r);
        down = (y - r < 0 ? 0 : y - r);
        
        f(i, left, right) {
            f(j, down, up) {
                if ((i - x) * (i - x) + (j - y) * (j - y) <= r * r)
                    range[i][j] = true;
            }
        }
    }

    f(i, 0, w) {
        f(j, 0, h) {
            if (range[i][j]) num++;
        }
    }
    
    cout << num;
    return 0;
}

8、清理水草

#include<iostream>
using namespace std;
const int N=1e2+10;
int n,m,t;
bool ran[N][N]; 
int main()
{
   int num=0;
   scanf("%d%d%d",&n,&m,&t);
   while(t--)
   {
   	int r1,c1,r2,c2;
   	scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
   	for(int i=r1;i<=r2;i++)
   	for(int j=c1;j<=c2;j++)
   	ran[i][j]=true;
   }
   for(int i=1;i<=n;i++)
   for(int j=1;j<=m;j++)
   if(!ran[i][j])num++;
   printf("%d",num); 
   return 0;
}

9、最长滑行距离

不会写

10、滑动窗口

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int k;
    cin >> k;
    vector<int> q1(n);
    vector<int> q2(n);
    vector<int> res(n);
    int hh = 0, tt = -1;
    for(int i = 0; i < n; i++){
        if(hh <= tt && q1[hh] < i - k) {
            hh++;
        }
        while(hh <= tt && a[q1[tt]] >= a[i]) {
            tt--;
        }
        q1[++tt] = i;
        res[i] = a[q1[hh]];
    }
    hh = 0;
    tt = -1;
    for(int i = n - 1; i >= 0; i--){
        if(hh <= tt && q2[hh] > i + k) {
            hh++;
        }
        while(hh <= tt && a[q2[tt]] >= a[i]) {
            tt--;
        }
        q2[++tt] = i;
        res[i] = min(res[i], a[q2[hh]]);
    }
    for(int i = 0; i < n; i++){
        cout << res[i] << " ";
    }
    return 0;
}

11、

223321

12、叠绳子

#include<iostream>
using namespace std;

typedef long long ll;

//ll n;

int cnt=0;
double n;

int main(){
	cin>>n;
	while(1){
		if(n<=1){
			cout<<cnt<<endl;
			break;
		}
		
		cnt++;
		n/=2.0;
		//n=>>1;
	}
	return 0;
}

13、给一个字符串删m个使得字符串字典序最小

#include <iostream>
#include <string>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    string str;
    cin >> str;

    string result = "";

    int deleteCount = 0;	//标记当前所要删除的个数是否达标 

    for (int i = 0; i < n; i++) {
        char c = str[i];	//将其取出来判断字典集大小 
        //cout << c; 

        //LANQIAO
        //AIAO
        while (deleteCount < m && result.length() > 0 && result[result.length() - 1] > c) {
            //当前所删除的未达标、结果集的长度大于0 且字符串的最后一位元素的字典集大于所取出来的 
            result.pop_back();
            deleteCount++;
        }

        result += c;	//将其加入结果字符串 
        //L 
        //A
        //AN
        //ANQ
        //AI
        //AIA
        //AIAO
    }

    if (deleteCount < m) {	//将后续所差的全部删去 
        int tmp = m - deleteCount;
        result.erase(result.length() - tmp, result.length());
    }

    cout << result << endl;
    return 0;
}

  • 6
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 15
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值