蓝桥杯2023年试题A

欧某上分之路——笔记走起,又收获一个!

狐狸说:今天这是第一次,记得下次再来哦!

 点击下面链接直达:

蓝桥杯B组省赛

题目描述:

代码

法1:

#include <bits/stdc++.h>
using namespace std;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
set<int> res;

void check(int m, int d) {
    if (m < 1 || m > 12 || d < 1 || d > days[m]) return;
    res.insert(m * 100 + d);
}
int main () {
    int num[]={15,6,8,6,9,1,6,1,2,4,9,1,9,8,2,3,6,4,7,7,5,9
    ,5,0,3,8,7,5,8,1,5,8,6,1,8,3,0,3,7,9,2,7,0,5,8,8,5,7,0,9,9,
    1,9,4,4,6,8,6,3,3,8,5,1,6,3,4,6,7,0,7,8,2,7,6,8,9,5,6,5,6,1,4,0,1,0,0,9,4,8,0,9,1,2,8,5,0,2,5,3,3};
    for (int a = 0; a < 100; a ++) {
        if (num[a] != 2) continue;
        for (int b = a + 1; b < 100; b ++) {
            if (num[b] != 0) continue;
            for (int c = b + 1; c < 100; c ++) {
                if (num[c] != 2) continue;
                for (int d = c + 1; d < 100; d ++) {
                    if (num[d] != 3) continue;

                    for (int i = d + 1; i < 100; i ++)
                        for (int j = i + 1; j < 100; j ++)
                            for (int k = j + 1; k < 100; k ++)
                                for (int l = k + 1; l < 100; l ++)
                                    check(num[i] * 10 + num[j], num[k] * 10 + num[l]);
                }
            }
        }
    }
    cout << res.size() << endl;
    return 0;
}

思路:

  1.  八个变量——前面四个找到2023(很简单)——后面四个用函数验证是否成立
  2. 成立就插入,重复的就不会插入!
  3. 最后.size()计算!

总结: 

这道题目不会写,网上看的——但仔细想想感觉也不难!就是多了个容器,还有循环八个感觉太多此一举,然而这很有必要暴力!

set<int> res;

res.insert()——如果添加重复的数据,就不会添加进去!

res.size()——计算里面添加的数据!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值