【蓝桥杯】考前冲刺!

在这里插入图片描述

个人主页:Guiat
归属专栏:算法竞赛

在这里插入图片描述

正文

总共6道真题,围绕蓝桥杯高频考点逐一展开。

1. 暴力枚举 — 好数

【题目】好数

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int N, digit, cnt;

bool check(int n)
{
    digit = 1;
    while (n)
    {
        if (digit % 2 == 1) { if ((n % 10) % 2 == 0) return false; }
        else { if ((n % 10) % 2 != 0) return false; }
        digit ++; n /= 10;
    }
    return true;
}

void solve()
{
    cin >> N;
    for (int i = 1; i <= N; i ++) if (check(i)) cnt ++;
    cout << cnt << '\n';
}

int main()
{
    IOS; int _ = 1; // cin >> _;
    while (_ --) solve();
    
    return 0;
}

2. 打表规律 — 数字诗意

【题目】数字诗意

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;

int n, cnt; ll a;

void solve()
{
    cin >> n;
    for (int i = 0; i < n; i ++)
    {
        cin >> a;
        for (int j = 0; j <= 54; j ++)
        {
            if (a == pow(2, j)) cnt ++;
        }
    }
    cout << cnt << '\n';
}

int main()
{
    IOS; int _ = 1; // cin >> _;
    while (_ --) solve();
    
    return 0;
}

3. 数论入门 — 宝石组合

【题目】宝石组合

【AC_Code】

#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int MAXN = 1e5 + 10; int n, h[MAXN]; vector<int> fac[MAXN];

void solve()
{
    cin >> n; for (int i = 1; i <= n; ++ i) cin >> h[i];
    sort(h + 1, h + 1 + n);
    for (int i = 1; i <= n; ++ i) for (int j = 1; j * j <= h[i]; ++j)
	{
        if (h[i] % j == 0)
		{
            fac[j].push_back(h[i]);
            if (h[i] / j != j) fac[h[i] / j].push_back(h[i]);
        }
    }

    for (int i = MAXN; i >= 1; -- i)
	{
        if (fac[i].size() >= 3)
		{
            int a = fac[i][0], b = fac[i][1], c = fac[i][2];
            if (__gcd(__gcd(a, b), c) == i) { cout << a << " " << b << " " << c << "\n"; return; }
        }
    }
}

int main()
{
    IOS; solve();

    return 0;
}

4. 排序策略 — 封闭图形个数

【题目】封闭图形个数

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, a, num, cnt[10] = { 1, 0, 0, 0, 1, 0, 1, 0, 2, 1 }, t;
vector<pair<int, int>> arr;

void solve()
{
    cin >> n;
    for (int i = 0; i < n; i ++)
    {
        cin >> a; t = a; num = 0;
        while (t) { num += cnt[t % 10]; t /= 10; }
        arr.push_back({ num, a });
    }
    sort(arr.begin(), arr.end());
    for (int i = 0; i < n; i ++) cout << arr[i].second << " \n"[i == n - 1];
}

int main()
{
    IOS; int _ = 1; // cin >> _;
    while (_ --) solve();
    
    return 0;
}

5. 贪心策略 — 训练士兵

【题目】训练士兵

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;

const int N = 1e6 + 10;
ll n, S, p, c, ans; map<ll, ll> mp;

void solve()
{
    cin >> n >> S;
    for (int i = 1; i <= n; i ++) { cin >> p >> c; mp[c] += p; }
    for (int i = N; i >= 1; i --) mp[i] += mp[i + 1];    // 后缀和 
    for (int i = 1; i <= N; i ++) ans += min(S, mp[i]);
    cout << ans << '\n';
}

int main()
{
    IOS; int _ = 1; // cin >> _;
    while (_ --) solve();
    
    return 0;
}

6. 哈希技巧 — 团建

【题目】团建

【AC_Code】

#include <bits/stdc++.h>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 2e5 + 10;
int n, m, c[N], d[N], u, v, ans;
map<int, vector<int>> m1, m2;

void dfs(int x, int y, int cnt)
{
    if (c[x] != d[y]) return ;
    ans = max(ans, cnt + 1);
    for (int i = 0; i < m1[x].size(); i ++)
        for (int j = 0; j < m2[y].size(); j ++)
            dfs(m1[x][i], m2[y][j], cnt + 1);
}

void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) cin >> c[i];
    for (int i = 1; i <= m; i ++) cin >> d[i];
    for (int i = 1; i <= n - 1; i ++) cin >> u >> v, m1[u].push_back(v);
    for (int i = 1; i <= m - 1; i ++) cin >> u >> v, m2[u].push_back(v);
    dfs(1, 1, 0); cout << ans << '\n';
}

int main()
{
    IOS; int _ = 1; // cin >> _;
    while (_ --) solve();
    
    return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

资源下载链接为: https://pan.quark.cn/s/1bfadf00ae14 在 Linux 系统中,查找域名或主机名对应的 IP 地址是网络管理中的一项基础且关键任务,对于排查网络故障、调试网络问题以及监控网络服务是否正常运行等场景都非常重要。本文将介绍五种在 Linux 终端查询域名 IP 地址的方法。 首先,dig 命令(全称 Domain Information Groper)是一个功能强大的 DNS 查询工具,能够向 DNS 服务器发送查询请求并获取详细的响应信息。如果需要查询单个域名的 IP 地址,可以使用命令 dig 2daygeek.com +short 。此外,还可以通过编写 bash 脚本,将包含域名的文本文件中的域名逐个读取,然后利用 dig 命令进行查询,从而实现批量查询域名 IP 地址的功能。 其次,host 命令是一个简单易用的 DNS 查询工具,主要用于将域名解析为 IP 地址。要获取某个域名的 IP 地址,直接使用 host 2daygeek.com 即可。如果只想显示 IP 地址部分,可以通过管道结合 grep 和 sed 命令来实现,例如:host 2daygeek.com | grep "has address" | sed s/has address/-/g 。 再者,nslookup 命令也是一种常用的 DNS 查询工具,它支持交互式查询 DNS 信息。通过 nslookup 2daygeek.com 可以查询域名的 IP 地址。若要以非交互式的方式只显示 IP 地址,可以使用命令 nslookup 2daygeek.com | awk /^Address:/ {print $2} 。 另外,fping 命令与传统的 ping 命令不同,它不会直接进行 DNS 查询,而是通过发送 ICMP Echo Request(pi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Guiat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值