首页 > 其他分享 >2024 蓝桥杯模拟赛 1

2024 蓝桥杯模拟赛 1

时间:2024-01-26 19:23:35浏览次数:23  
标签:2024 int cin long 蓝桥 ans using 模拟 mod

P8761 [蓝桥杯 2021 国 BC] 大写

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;


i32 main() {
    string s;
    cin >> s;
    for( auto & i : s ){
        if( i >= 'a' and i <= 'z' ) cout << char( i - 'a' + 'A');
        else cout << i;
    }
    return 0;
}

P8195 [传智杯 #4 决赛] 小智的疑惑

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;


i32 main() {
    string s;
    cin >> s;
    int res = 0;
    for( int i = 0 ; i + 8 <= s.size() ; i ++ ){
        if( s.substr( i , 8 ) == "chuanzhi" ) res ++;
    }
    cout << res << "\n";
    return 0;
}

P8651 [蓝桥杯 2017 省 B] 日期问题

注意去重

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

int t[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

i32 main() {
    int a, b, c;
    cin >> a, cin.ignore();
    cin >> b, cin.ignore();
    cin >> c, cin.ignore();
    int y, m, d;
    set<array<int, 3>> res;

    if (a <= 59) y = a + 2000;
    else y = a + 1900;
    m = b, d = c;
    if ( m >= 1 and m <= 12) {
        if (m != 2) {
            if (d >= 1 and d <= t[m]) res.insert({y, m, d});
        } else {
            if ((y % 4 == 0 and y % 100 != 0) or (y % 400) == 0) {
                if (d >= 1 and d <= 29) res.insert({y, m, d});
            } else if (d >= 1 and d <= 28)res.insert({y, m, d});
        }
    }

    if (c <= 59) y = c + 2000;
    else y = c + 1900;
    m = a, d = b;
    if (m >= 1 and m <= 12) {
        if (m != 2) {
            if (d >= 1 and d <= t[m]) res.insert({y, m, d});
        } else {
            if ((y % 4 == 0 and y % 100 != 0) or (y % 400) == 0) {
                if (d >= 1 and d <= 29) res.insert({y, m, d});
            } else if (d >= 1 and d <= 28)res.insert({y, m, d});
        }
    }
    if (c <= 59) y = c + 2000;
    else y = c + 1900;
    m = b, d = a;
    if (m >= 1 and m <= 12) {
        if (m != 2) {
            if (d >= 1 and d <= t[m]) res.insert({y, m, d});
        } else {
            if ((y % 4 == 0 and y % 100 != 0) or (y % 400) == 0) {
                if (d >= 1 and d <= 29) res.insert({y, m, d});
            } else if (d >= 1 and d <= 28)res.insert({y, m, d});
        }
    }
    for (auto [x, y, z]: res)
        printf("%d-%02d-%02d\n", x, y, z);
    return 0;
}

P9240 [蓝桥杯 2023 省 B] 冶炼金属

两次二分

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

i32 main() {
    int n;
    cin >> n;
    vector<pii> a(n);
    for (auto &[x, y]: a) cin >> x >> y;
    int l = 1, r = inf, res = -1;
    for (int mid, flag; l <= r;) {
        mid = (l + r) / 2, flag = 1;
        for (const auto &[x, y]: a) {
            if (x / mid <= y) continue;
            flag = 0;
            break;
        }
        if (flag) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << res << " ";
    l = 1, r = inf, res = -1;
    for (int mid, flag; l <= r;) {
        mid = (l + r) / 2, flag = 1;
        for (const auto &[x, y]: a) {
            if (x / mid >= y) continue;
            flag = 0;
            break;
        }
        if (flag) res = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << res << "\n";
    return 0;
}

P8627 [蓝桥杯 2015 省 A] 饮料换购

模拟

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    int n, res = 0;
    cin >> n;
    for (int a = n, b = 0; a > 0 or b >= 3; a = b / 3, b %= 3)
        res += a, b += a, a = 0;
        cout << res << "\n";
    return 0;
}

P8647 [蓝桥杯 2017 省 AB] 分巧克力

二分

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    int n, m;
    cin >> n >> m;
    vector<pii> a(n);
    for (auto &[x, y]: a) cin >> x >> y;
    int l = 1, r = 1e5, res = -1;
    for (int mid, cnt; l <= r;) {
        mid = (l + r) / 2, cnt = 0;
        for (const auto &[x, y]: a)
            cnt += (x / mid) * (y / mid);
        if (cnt >= m) res = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << res << "\n";

    return 0;
}

P8637 [蓝桥杯 2016 省 B] 交换瓶子

直接从小到大,每次判断瓶子在不在位置上,如果不在就进行一次交换

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++)
        cin >> a[i], a[i]--, b[a[i]] = i;
    int res = 0;
    for (int i = 0, x, y, p, q; i < n; i++) {
        if (b[i] == i) continue;
        res++;
        x = i, y = a[i], p = b[x], q = b[y];
        swap(a[p], a[q]), swap(b[x], b[y]);
    }
    cout << res << "\n";
    return 0;
}

P8625 [蓝桥杯 2015 省 B] 生命之树

其实就是求树上的最大连通块,所以直接进行树形dp,枚举每个叶子选不选即可

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    int n, res = 0;
    cin >> n;
    vector<int> f(n);
    for (auto &i: f) cin >> i;
    vector<vi> e(n);
    for (int i = 1, u, v; i < n; i++)
        cin >> u >> v, --u, --v, e[u].push_back(v), e[v].push_back(u);
    auto dfs = [&res, &f, e](auto &&self, int x, int fa) -> void {
        for (const auto &y: e[x]) {
            if (y == fa)continue;
            self(self, y, x);
            f[x] += max(0ll, f[y]);
        }
        res = max(res, f[x]);
    };

    dfs(dfs, 0, -1);
    cout << res << "\n";

    return 0;
}

P8638 [蓝桥杯 2016 省 A] 密码脱落

把原序列反序之后求一下lcs就行

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    string a, b;
    cin >> a, b = a, reverse(b.begin(), b.end());
    int n = a.size();
    a = " " + a, b = " " + b;
    auto f = vector(n + 1, vi(n + 1));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            if (a[i] == b[j]) f[i][j] = f[i - 1][j - 1] + 1;
            else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
    cout << n - f[n][n] << "\n";

    return 0;
}

P8774 [蓝桥杯 2022 省 A] 爬树的甲壳虫

几何概型,求出每一步所需要爬的次数即可

#include<bits/stdc++.h>

using namespace std;

#define int long long
using vi = vector<int>;
using i32 = int32_t;
using pii = pair<int, int>;

const int inf = 1e9, INF = 1e18;

const int mod = 998244353;

int power(int x, int y) {
    int ans = 1;
    while (y) {
        if (y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

i32 main() {
    int n, res = 0;
    cin >> n;
    for (int x, y; n; n--)
        cin >> x >> y, res = (res + 1) * y % mod * inv(y - x) % mod;
    cout << res << "\n";
    return 0;
}

标签:2024,int,cin,long,蓝桥,ans,using,模拟,mod
From: https://www.cnblogs.com/PHarr/p/17990524

相关文章

  • Hello 2024
    AWalletExchange题目大意Alice有a个硬币,Bob有b个硬币,双方轮流进行以下操作:1.与对方交换硬币,或者保留现有硬币.2.取出一个硬币无法进行操作的人判定为输,总是从Alice开始操作问:哪位获得胜利解题思路我们可以把游戏看作是轮流取硬币,取得最后一个硬币的为胜利那......
  • PKUWC 2024 Day 1
    大致的题面如下:T1Alice和Bob玩游戏。有一个长度为\(N\)的字符串\(S\),由L和R组成。Alice先手,Bob后手。他们可以:选择一个\(i\)。如果\(S_i\)=L,那么只保留\(S_{1\simi-1}\)。如果\(S_i\)=R,那么只保留\(S_{i+1,|S|}\)。第一个遇到\(S\)空了的输掉。问谁会......
  • [office] 将模拟运算表转换为图表
    如果需要更加直观地查看和比较数据,还可以将计算结果转换为图表,下面就将双变量模拟运算表转换为图表,将模拟运算表转换为图表操作方法如下:1、在工作表Sheet6中对表格进行美化。选择单元格B2,按下Delete键,将计算结果清除。图12、选择单元格区域A2:E8,切换到【插入】选......
  • 2024年1月Java项目开发指南14:关于post中的body和param以及java中的@RequestBody和@Req
    在HTTP请求中,POST方法通常用于向服务器发送数据,这些数据可以在请求的body中,也可以在URL的param中。不过,这两者的使用方式和适用场景是不同的。Body:在POST请求中,body主要用于包含要发送到服务器的数据。这些数据通常是表单数据、JSON数据或其他类型的数据。当你需要在请求体中发送......
  • SMU 2024 winter round1
    7-1最好的文档#include<bits/stdc++.h>usingnamespacestd;usingi32=int32_t;i32main(){ios::sync_with_stdio(false),cin.tie(nullptr);cout<<"Goodcodeisitsownbestdocumentation.";return0;}7-2自动编程#includ......
  • 2024年可以提高工作效率的待办事项提醒软件
    对于上班族来说,追求升职加薪始终是一个不断努力的目标,而提升工作效率则成为必备的一环。在繁忙的工作生活中,一个可靠的待办事项提醒软件就成了事业成功的得力助手。那么2024年口碑很好的待办事项提醒软件是哪个呢?在2024年,备受好评的待办事项提醒软件中,敬业签成为许多上班族的选择......
  • 20240126打卡——《构建之法》第5~8章
    第五章团队和流程5.2软件团队的模式主治医师模式、明星模式、社区模式、业余剧团模式、秘密团队、特工团队、交响乐团模式、爵士乐模式、功能团队模式、官僚模式5.3开发流程①写了再改模式②瀑布模型(WaterfallModel)是一个项目开发架构,开发过程是通过设计一系列阶段顺序......
  • P10083 [GDKOI2024 提高组] 不休陀螺
    前置题目:石头剪刀布大赛很经典的问题,可以参考一个比这个简单容易想的*2500的做法。先想判定条件再考虑怎么计数。因为少写了一个case导致Au\(\to\)Ag,有点难评。不难想到记录\(c_i=b_i-a_i\)。我们考虑怎样才能无限下去:卡牌打完之后的费用变化是正的,不然会一直......
  • THUWC2024 游记
    已经是老年选手了。Day0从成都坐车到重庆。到酒店就四点多了,打了个车去巴蜀,车上学弟问师傅有什么火锅店推荐,然后司机直接给我们送过去了(?)火速签到,火速试机,然后监考下班了(?)后来又说加班半个小时,登了下OJ写了个A+B就run了。见到了清华学长cxy哥哥!!!晚上把路上口胡的题写......
  • 2024-01-26 yarn证书源过期 ==》 yarn切换的镜像源为https,实际上该链接的证书已过期,应
    如,我给一个项目用yarn装依赖,这时候报错:yarninstallv1.22.21infoNolockfilefound.[1/4]Resolvingpackages...errorError:certificatehasexpiredatTLSSocket.onConnectSecure(node:_tls_wrap:1539:34)atTLSSocket.emit(node:events:513:28)atTLSSocket._fin......