码蹄杯 2024 初赛第一场

在这里插入图片描述

MC0301

求个最大值

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    cin >> n;
    int mx = -1;
    for(int i = 0;i < n;i ++){
        int x; cin >> x;
        mx = max(mx,x);
    }
    cout << mx << endl;
}

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

MC0302

sort一下

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n;

void solve(){
    vector<int> a(3);
    for(int i = 0;i < 3;i ++) cin >> a[i];
    sort(a.begin(),a.end());
    for(int i = 0;i < 3;i ++) cout << a[i] << " "; 
}

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

MC0303

看一下范围内有多少质数

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n;
int st[N]; 

int get_prime(){
    int cnt = 0;
    for(int i = 2;i <= n;i ++){
        if(st[i]) continue;
        cnt ++;
        for(int j = i + i;j <= n;j += i) st[j] = 1; 
    }
    return cnt;
}

void solve(){
    cin >> n;
    cout << get_prime() << endl;
}

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

MC0304

二分答案 然后check里去将每个 a i a_i ai减去二分的答案 看长度 f − n f-n fn的区间和
大于零更新 l 小于零更新 r

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n,f;
int a[N];

int check(double x){
    vector<double> b(n + 1);
    for(int i = 1;i <= n;i ++) b[i] = a[i] - x;
    vector<double> pre(n + 1);
    for(int i = 1;i <= n;i ++) pre[i] = pre[i - 1] + b[i];
    double mn = 1e18;
    for(int i = f;i <= n;i ++){
        mn = min(mn,pre[i - f]);
        if(pre[i] - mn >= 0) return 1; 
    }
    return 0;
}

void solve(){
    cin >> n >> f;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    double l = 1,r = 2000;
    while(r - l > 1e-6){
        double mid = (l + r) / 2;
        if(check(mid)) l = mid;
        else r = mid; 
    }
    cout << floor(r * 1000) << endl;
}

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

MC0305

模拟一下排名

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n;
int a[N];

void solve(){
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> a[i];
    sort(a,a + n,greater<int>());
    map<int,int> mp;
    int pos = 1;
    for(int i = 0;i < n;i ++){
        if(!mp[a[i]]) mp[a[i]] = pos ++;
        else pos ++;
    }
    int x; cin >> x;
    cout << mp[x] << endl;
}

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

MC0306

转化一下类型即可

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int n;
int a[N];

void solve(){
    char x; cin >> x;
    cout << (int)x << endl;
}

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

MC0307

存一下路径跑一遍bfs即可

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e6 + 7;
vector<int> g[N];
int n,x,y;

int bfs(){
    queue<int> q;
    q.push(x);
    vector<int> st(n + 1);
    vector<int> d(n + 1,1e9);
    d[x] = 0;
    st[x] = 1;
    while(q.size()){
        int t = q.front();
        q.pop();
        for(auto root : g[t]){
            if(st[root]) continue;
            d[root] = min(d[t] + 1,d[root]);
            if(root == y) return d[y];
            q.push(root);
            st[root] = 1;  
        }
    }
    return -1;
}

void solve(){
    cin >> n >> x >> y;
    for(int i = 1;i <= n;i ++){
        int len; cin >> len;
        int u = i;
        int v1 = i + len,v2 = i - len;
        if(v1 <= n) g[u].push_back(v1);
        if(v2 >= 1) g[u].push_back(v2); 
    }
    cout << bfs();
}

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

MC0308

统计一遍大写字符

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    string s; getline(cin,s);
    int ans = 0;
    for(int i = 0;i < s.size();i ++){
        if(s[i] >= 'A' && s[i] <= 'Z') ans ++;
    }
    cout << ans;
}

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

MC0309

拆位统计每位的个数
然后分别算一下按位与 和 按位或的贡献

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int a[N];
int n;

void solve(){
    cin >> n;
    for(int i = 0;i < n;i ++) cin >> a[i];
    map<int,int> mp;
    int ans = 0;
    for(int i = 0;i < n;i ++) ans += a[i];
    for(int i = 0;i < 32;i ++){
        for(int j = 0;j < n;j ++){
            int cnt = a[j] >> i;
            if(cnt & 1) mp[i] ++;
        }
        ans += mp[i] * (n - 1 + n - mp[i]) / 2 * ((int)1 << i);
        if(mp[i] > 1) ans += mp[i] * (mp[i] - 1) / 2 * ((int)1 << i);
    }
    cout << ans << endl;
}

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

MC0310

reverse一下

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7;
int a[N];
int n;

void solve(){
    string s; cin >> s;
    reverse(s.begin(),s.end());
    cout << s;
}

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

MC0311

模拟

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

void solve(){
    map<int,int> mp;
    int space = 0;
    for(int i = 0;i < 8;i ++){
        int x; cin >> x;
        mp[x] ++;
        if(mp[x] == 3){
            space += 2;
            mp[x] = 0;
            mp[x * 10] ++;
        }
    }
    int n; cin >> n;
    for(int i = 0;i < n;i ++){
        int x; cin >> x;
        if(mp[x] == 2){
            mp[x] = 0;
            mp[x * 10] ++;
            space += 1;
            if(mp[x * 10] == 3){
                mp[x * 10] = 0;
                mp[x * 100] ++;
                space += 1;
                if(mp[x * 100] == 3){
                    mp[x * 100] = 0;
                    mp[x * 1000] ++;
                    space += 1;
                }
            }
        } else if(space){
            mp[x] ++;
            space --;
        }
    }
    int op; cin >> op;
    if(mp.rbegin()->first >= op) cout << "YES YES YES";
    else cout << "NO NO NO";
}

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

MC0312

直接erase 或者 更新删除位置开始以后的数组的值为他之后的值复杂度也是可以的

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

int n,m; 

void solve(){
    cin >> n;
    vector<int> a;
    for(int i = 1;i <= n;i ++){
        int x; cin >> x;
        a.push_back(x); 
    }
    cin >> m;
    for(int i = 1;i <= m;i ++){
        int pos; cin >> pos;
        a.erase(a.begin() + pos - 1);
    }
    for(auto x : a) cout << x << " ";
}

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

MC0313

暴力枚举

code:

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 7; 
int n,m; 
int a[N];

void solve(){
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    a[n + 1] = a[1],a[n + 2] = a[2],a[n + 3] = a[3];
    int pos = 0,sum = 0;
    int mx = -1;
    for(int i = 1;i <= n;i ++){
        sum = a[i] + a[i + 1] + a[i + 2] + a[i + 3];
        if(sum > mx) mx = sum,pos = i;
    }
    cout << mx << endl << pos << endl; 
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int _ = 1; 
    while(_ --){
        solve();
    }
    return 0;
}
  • 50
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
第六届传智杯B组初赛是传智播客举办的一次IT技术竞赛的初赛阶段,旨在选拔出各高校优秀的程序设计人才。该比赛中,参赛者将面临多道编程题目,通过编写程序解决问题来展示他们的技术水平和创新能力。 在初赛中,参赛者需要在规定的时间内完成多道程序设计题目。这些题目可能涉及数据结构、算法、网络通信等方面的知识,要求参赛者具备扎实的编程基础和解决实际问题的能力。 参赛者需要在规定的时间内完成编程题目,并提交给评委进行评分。评委会根据答案的正确性、效率、代码的可读性等方面对参赛者的作品进行综合评判。最终,得分高的参赛者将进入下一轮比赛。 第六届传智杯B组初赛的目的是为了选拔出具备优秀编程能力的学生,为他们提供一个展示才华、学习交流的平台。参赛者不仅可以通过比赛锻炼自己的编程技巧,还可以结识其他优秀的参赛者,相互学习、切磋技艺。 在比赛过程中,参赛者还可以通过与其他选手交流,了解各种不同的编程思路和解题方法,不断提高自己的编程水平。同时,参赛者还有机会与业界的专家学者进行交流,了解最新的技术动态和发展趋势。 总之,第六届传智杯B组初赛是一次很有意义的编程竞赛,为各大高校的IT人才选拔提供了一次难得的机会。通过比赛,参赛者可以展现自己的才华,提升技术水平,同时也可以与其他优秀选手进行交流,共同进步。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值