首页 > 其他分享 >230606蓝桥训练

230606蓝桥训练

时间:2023-06-06 21:33:06浏览次数:46  
标签:230606 cout 训练 int cin long 蓝桥 fa using

重现

A-数数

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s;
    set<char> cnt;
    cin >> s;
    for( auto c : s )
        cnt.insert(c);
    cout << cnt.size() << "\n";
    return 0;
}

B-二进制?十进制!

#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int a, b;
    vector<int> c;
    cin >> a >> b;
    if (a < b) swap(a, b);

    while (a) c.push_back(a & 1), a >>= 1;

    for (int i = 0; b > 0 && i < c.size(); i++)
        c[i] += b & 1, b >>= 1;
    reverse(c.begin(), c.end());
    for (auto i: c)
        cout << i;
}

C-夹娃娃

#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);

    int n , k;
    cin >> n >> k;
    vector<int> a( n+1 );
    for( int i = 1 ; i <= n ; i ++ )
        cin >> a[i] , a[i] += a[i-1];
    for( int l , r ; k ; k -- ){
        cin >> l >> r;
        cout << a[r] - a[l-1] << "\n";
    }
}

D-子序列

贪心的向肯定是开头加一个a或则结尾加一个b两种。这注意题会爆long long

#include <bits/stdc++.h>

using namespace std;

#define int unsigned long long

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    string x, y;
    cin >> x;
    y = x + "b", x = "a" + x;
    int f = 0, g = 0, ans = 0, res = 0, n = x.size();
    for (int i = 0; i < n; i++) {
        if (x[i] == 'a') f++;
        else ans += f * (f - 1) / 2;

        if (y[i] == 'a') g++;
        else res += g * (g - 1) / 2;
    }
    cout << max(ans, res);
}

E-小L的编辑器

list模拟一下

#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, res = 0;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    list<char> res;
    auto it = res.begin();
    string s, t;
    cin >> s >> t;
    int n = s.size();

    for (int i = 0; i < n; i++) {
        res.insert(it, s[i]);
        if( t[i] == 'L' ) it --;
    }
    for( auto i : res )
        cout << i;
}

F-答题卡

dp写法。\(f[i]\)表示$i\times i \(的答题卡的方案数。考虑第一列的放置情况。如果放在\)(1,1)\(则考虑剩下\)i-1\(列,如果放\)(1,x)\(,这相当于和\)(x,1)\(交换位置,还要考虑剩下\)i-2\(列,这里\)x\(的取值是\)i-1\(。所以\)f[i]=f[i-1]+(i-1)\times f[i-2]$

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int mod = 1e9+7;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> f(n+1);
    f[0] = f[1] = 1;
    for( int i = 2 ; i <= n ; i ++ )
        f[i] = f[i-1] + (i-1) * f[i-2] , f[i] %= mod;
    cout << f[n];
}

G-牛牛的数列

首先要找的\(a_i \oplus s\)的最大值,所以令\(b_i=a_i\oplus s\)然后用 st 表维护一下最值即可。

这里要找\(k\)其实没有用,找到\(b_i\)后求出\(a_i\)就好了。然后\(S\)可以前缀异或和计算。

\(W\)其实可以自己从高位枚举每一个二进制位选或不选即可。

#include <bits/stdc++.h>

using namespace std;

int read() {
    int x = 0, ch = getchar();
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x;
}

int32_t main() {
    int n = read(), q = read(), s = read(), w = read();
    vector<int> b(n + 1), c(n + 1);
    for (int i = 1, x; i <= n; i++)
        x = read(), b[i] = x ^ s, c[i] = c[i - 1] ^ x;
    const int logN = log2(n) + 1;


    vector<int> p(1);
    p[0] = 1;
    while (p.size() < logN || p.back() < w)
        p.push_back(p.back() * 2ll);

    vector<vector<int>> f(n + 1, vector<int>(logN, 0));
    for (int i = 1; i <= n; i++) f[i][0] = b[i];
    for (int j = 1; j < logN; j++)
        for (int i = 1; i + p[j - 1] <= n; i++)
            f[i][j] = max(f[i][j - 1], f[i + p[j - 1]][j - 1]);

    auto getMax = [f, p](int l, int r) {
        int s = r - l + 1, j = log2(s);
        return max(f[l][j], f[r - p[j] + 1][j]);
    };
    for (int l, r, aj, S, m; q; q--) {
        l = read(), r = read();
        aj = getMax(l, r) ^ s, S = c[r] ^ c[l - 1] ^ aj;
        for (int i = p.size() - 1, m = w; i >= 0; i--) {
            if (p[i] > m || S & p[i]) continue;
            S ^= p[i], m -= p[i];
        }
        printf("%d\n", S);

    }
    return 0;

}

H-小y的旅行

采取了一种贪心的思路,首先把和前\(k\)个点无关的边全部都加进去,然后把枚举剩下的边,用并查集判断如果加边后成环了就不加边,否则就加边。

#include <bits/stdc++.h>
using namespace std;

struct dsu{
    int n;
    vector<int> fa;
    dsu( int n = 0 ) : n(n) , fa( n + 1 , -1 ) {};

    int getfa( int x ){
        if( fa[x] < 0 ) return x;
        return fa[x] = getfa(fa[x]);
    }

    bool check( int & x , int &y ){
        x = getfa(x) , y = getfa(y);
        return x == y;
    }

    bool merge( int x , int y ){
        if( check(x,y) ) return false;
        if( fa[x] > fa[y] ) swap( x , y );
        fa[x] += fa[y] , fa[y] = x;
        return true;
    }
};

int main(){
    int n , m , k;
    cin >> n >> m >> k;
    vector<pair<int,int>> e;
    dsu d(n);
    for( int x , y ; m; m--){
        cin >> x >> y;
        if( x > y ) swap( x , y );
        if( x <= k ) e.emplace_back( x , y );
        else d.merge( x , y );
    }
    int res = 0;
    for( auto [x,y] : e )
        if( d.merge( x , y ) == false ) res ++;
    cout << res;
}

标签:230606,cout,训练,int,cin,long,蓝桥,fa,using
From: https://www.cnblogs.com/PHarr/p/17461780.html

相关文章

  • 202306062001-《远程Linux服务器——安装tomcat8、jdk1.8、mysql5——mysql 用sql建表
    因createtable...提示格式错误,什么NAME啊...,必查了一下,要设置,好多条语句(5条左右),是设置格式的。 但设置完了,说重启mysql,就失效,要重新设置(5条sql重新执行一遍!) 永久有效的解决办法是:修改“my.cnf”,我的修改如下:[client]default-character-set=utf8[mysql]default-......
  • Yolov5训练时出现loss出现nan值或者测试时P\R\map全部为0值的解决办法
    问题:train训练得出的P\R\map全部为0上网寻找寻找答案,大部分给出的原因解释如下:①文件夹格式(名称和架构)有问题,这属于基本内容,不应该出错的。②pytorch和cuda版本不对应。关于这部分可以参考链接:https://blog.csdn.net/jhsignal/article/details/111401628 和 https://www......
  • 2.1类神经网路训练不起来怎么办 (一):局部最小值 (local minima) 与鞍点 (saddle poin
    1.Whengradientissmall  本小节主要讨论优化器造成的训练问题.1.1CriticalPoint(临界点)  如果训练过程中经过很多个epoch后,loss还是不下降,那么可能是因为梯度(斜率)接近于0,导致参数更新的步伐接近于0,所以参数无法进一步更新,loss也就降不下去.  这时或许有很......
  • 代码随想录算法训练营第二十八天|93. 复原 IP 地址
    【参考链接】93.复原IP地址【注意】1.切割问题就可以使用回溯搜索法把所有可能性搜出来。2.startIndex一定是需要的,因为不能重复分割,记录下一层递归分割的起始位置。3.本题我们还需要一个变量pointNum,记录添加逗点的数量。4.分割的段数作为终止条件。pointNum表示逗点数......
  • 蓝桥题记 01
    10道题蓝桥杯题记1.单词分析难度简单题目https://www.lanqiao.cn/problems/504/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=3 #include<iostream> usingnamespacestd; intmain() {  //请在此输入您的代码  stringarr;......
  • 从0到1:如何建立一个大规模多语言代码生成预训练模型
    国产AI辅助编程工具CodeGeeX是一个使用AI大模型为基座的辅助编程工具,帮助开发人员更快的编写代码。可以自动完成整个函数的编写,只需要根据注释或Tab按键即可。它已经在Java、JavaScript和Python等二十多种语言上进行了训练,并基于大量公开的开源代码、官方文档和公共论坛上的代码来......
  • (贪心+搜索+剪枝)P8801 [蓝桥杯 2022 国 B] 最大数字
    题目描述给定一个正整数 N。你可以对 N 的任意一位数字执行任意次以下2种操作:将该位数字加 1。如果该位数字已经是 9,加 1 之后变成 0。将该位数字减 1。如果该位数字已经是 0,减 1 之后变成 9。你现在总共可以执行 1 号操作不超过 A 次,2 号操作不......
  • 【蓝桥杯集训·每日一题】AcWing 3805. 环形数组
    写在前面本人CSDN博客主页:这里一、题目1、原题链接3805.环形数组2、题目描述给定一个长度为n的环形数组a0,a1,…,an−1。现在要对该数组进行m次操作。操作分为以下两种:增值操作lrd,将区间[l,r]上的每个元素都增加d。求最小值操作lr,输出区间[l,r]内的所有元素的最小......
  • 【2023华为云CodeArts Build 实战训练营】云端实战-玩转编译构建
    2023HDC华为开发者大会即将到来,一起跟小智提前体验华为云CodeArtsBuild请注册华为云账号并完成实名认证,实验过程中请使用Chrome浏览器完成相关操作。华为云账号注册步骤请参考:https://support.huaweicloud.com/usermanual-account/zh-cn_topic_0069252244.html实名认证操作步骤请......
  • 蓝桥杯----动态规划训练
    最长上升子序列 之前我定义的dp是:dp[n][i]:表示在前n个数中选,并以数a[i]结尾的最长上升序列但是这个状态的转移有点不自然,感觉就想有很多多余的感觉if(i<=n-1)dp[n][i]=dp[n-1][i]if(a[i]>a[j]&&j<=n-1)dp[n][i]=max(dp[n][i],dp[......