【码蹄集】— 码蹄杯 2023省赛第一场

MC0201

a + b a+b a+b

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    int a,b; cin >> a >> b;
    cout << a + b << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    while(_ --){
        solve();
    }
    return 0;
}

MC0202

暴力枚举

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    int l,r; char x; cin >> l >> x >> r;
    int sum = 0;
    for(int i = l;i <= r;i ++){
        if(i % 2 || i % 3) continue;
        sum += i;
    }
    cout << sum << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    while(_ --){
        solve();
    }
    return 0;
}

MC0203

map更新分数和最后一次操作的位置即可

然后找最小分数 如果最小分数相同就看更新的位置

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    cin >> n;
    map<string,pair<int,int>> mp;
    for(int i = 0;i < n;i ++){
        string s; cin >> s;
        int x; cin >> x;
        mp[s] = {x + mp[s].first,i};
    }
    int mn = 1e18,pos = 1e18;
    string ans;
    for(auto x : mp){
        if(x.second.first < mn) mn = x.second.first,ans = x.first,pos = x.second.second;
        else if(x.second.first == mn && x.second.second < pos) mn = x.second.first,ans = x.first,pos = x.second.second;
    }
    cout << ans << endl;
    cout << mn + 1000 << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    while(_ --){
        solve();
    }
    return 0;
}

MC0204

求最长连续不重复子序列长度

双指针即可

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e6 + 7;
int n;
int c[N];

void solve(){
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> c[i];
    map<int,int> mp;
    int mx = 1;
    for(int i = 0,j = 0;i < n;i ++){
        mp[c[i]] ++;
        while(j < i && mp[c[i]] > 1) mp[c[j ++]] --;
        mx = max(i - j + 1,mx);
    }
    cout << mx << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    while(_ --){
        solve();
    }
    return 0;
}

MC0205

找最大字符

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    string s; cin >> s;
    char ans = *max_element(s.begin(),s.end());
    cout << ans << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1;
    while(_ --){
        solve();
    }
    return 0;
}

MC0206

只会有两种情况:

ABABAB...

BABABA...

看两种情况最低处理操作即可

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    string s; cin >> s;
    int n = s.size();
    int ans1 = 0,ans2 = 0;
    for(int i = 0;i < n;i ++){
        if(i % 2){
            if(s[i] == 'A') ans1 ++;
            else ans2 ++;
        } else{
            if(s[i] == 'B') ans1 ++;
            else ans2 ++;
        }
    }
    cout << min(ans1,ans2) << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}

MC0207

单向建图 dfs从1开始跑一遍看是否能到n即可

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 7;
vector<int> g[N];
int n,m;
int flag;
int st[N];

void dfs(int u){
    if(flag || u == n){
        flag = 1;
        return;
    }
    st[u] = 1;
    for(auto t : g[u]){
        if(st[t]) continue;
        dfs(t);
    }
}

void solve(){
    cin >> n >> m;
    for(int i = 0;i < m;i ++){
        int u,v; cin >> u >> v;
        g[u].push_back(v);
    }
    dfs(1);
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}

MC0208

看是否是10的倍数 不是就*2

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    cin >> n;
    if(n % 10) cout << 2 * n << endl;
    else cout << 0 << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}

MC0209

分长度奇偶即可

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    string s; cin >> s;
    n = s.size();
    if(n & 1) cout << "123456" << endl;
    else{
        reverse(s.begin() + n / 2,s.end());
        cout << s << endl;
    }
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}

MC0210

暴力判断即可

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    string s; cin >> s;
    n = s.size();
    for(int i = n / 3;i >= 1;i --){
        string s1 = s.substr(0,i);
        string s2 = s.substr(n - i,i);
        if(s1 == s2){
            string s3 = s.substr(i,n - 2 * i);
            if(s3.find(s1) != s3.npos){
                cout << s1 << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}

MC0211

模拟

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    string s; cin >> s;
    int pos = s.size() - 1;
    for(int i = pos;i >= 0;i --){
        if(s[i] != '0'){
            pos = i;
            break;
        }
    }
    if(s.size() == 1) cout << s << endl;
    else{
        cout << s[0];
        if(pos != 0) cout << ".";
        for(int i = 1;i <= pos;i ++) cout << s[i];
        cout << "E" << s.size() - 1 << endl;
    }
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}

MC0212

code:

cpp 复制代码

MC0213

按相同边长分类讨论

code:

cpp 复制代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    map<int,int> mp;
    for(int i = 0;i < 5;i ++){
        int x; cin >> x;
        mp[x] ++;
    }
    if(mp.size() == 1) cout << "Square" << endl;
    else if(mp.size() == 2){
        if(mp.begin()->second == 4 || mp.begin()->second == 1) cout << "Square" << endl;
        else cout << "Rectangle" << endl;
    } else if(mp.size() == 3){
        int cnt = 0;
        for(auto x : mp) if(x.second == 2) cnt ++;
        if(cnt == 2) cout << "Rectangle" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
} 

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}
相关推荐
不当菜鸡的程序媛7 小时前
Flow Matching|什么是“预测速度场 vt=ε−x”?
人工智能·算法·机器学习
sali-tec7 小时前
C# 基于halcon的视觉工作流-章58-输出点云图
开发语言·人工智能·算法·计算机视觉·c#
_OP_CHEN7 小时前
算法基础篇:(四)基础算法之前缀和
c++·算法·前缀和·蓝桥杯·acm·icpc·算法竞赛
_OP_CHEN7 小时前
算法基础篇:(五)基础算法之差分——以“空间”换“时间”
c++·算法·acm·icpc·算法竞赛·差分算法·差分与前缀和
DuHz8 小时前
霍夫变换和基于时频脊线的汽车FMCW雷达干扰抑制——论文阅读
论文阅读·物联网·算法·汽车·信息与通信·毫米波雷达
秋风&萧瑟8 小时前
【C++】智能指针介绍
java·c++·算法
QiZhang | UESTC8 小时前
JAVA算法练习题day67
java·python·学习·算法·leetcode
陌路208 小时前
S15 排序算法--归并排序
数据结构·算法·排序算法
智者知已应修善业8 小时前
【c# 想一句话把 List<List<string>>的元素合并成List<string>】2023-2-9
经验分享·笔记·算法·c#·list
B站_计算机毕业设计之家8 小时前
深度学习:python人脸表情识别系统 情绪识别系统 深度学习 神经网络CNN算法 ✅
python·深度学习·神经网络·算法·yolo·机器学习·cnn