AcWing 第99场周赛

在这里插入图片描述
手速win!

A 4950. 四则运算

直接输出!
手速win!

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    // cout << (a * b) * 1.0 / (b + c);
    printf("%.4f", (a * b) * 1.0 / (b + c));
    return 0;
}

B 4951.整理账本

pair排序,主要是读题。
手速win!
map本来是有序的,写复杂了,但是过了就行

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
signed main() {
    int n, m;
    cin >> n >> m;
    map<int, int> B, S;
    for (int i = 0; i < n; i++) {
        char c;
        int p, q;
        cin >> c >> p >> q;
        if (c == 'B') {
            B[p] += q;
        } else {
            S[p] += q;
        }
    }

    vector<pair<int, int>> a, b;
    for (auto x : B) {
        a.push_back({x.first, x.second});
    }
    for (auto x : S) {
        b.push_back({x.first, x.second});
    }
    sort(a.begin(), a.end(), [&](pair<int, int> x, pair<int, int> y) {
        return x.first > y.first;
    });
    sort(b.begin(), b.end(), [&](pair<int, int> x, pair<int, int> y) {
        return x.first < y.first;
    });

    for (int i = min(m, (int)b.size()) - 1; i >= 0; i--) {
        cout << "S " << b[i].first << " " << b[i].second << endl;
    }

    for (int i = 0; i < min(m, (int)a.size()); i++) {
        cout << "B " << a[i].first << " " << a[i].second << endl;
    }

    return 0;
}

C 4952. 扩展区间

贪心
就贪心的去扩展,优先扩展左边,可以扩展则优先扩展,然后在判断右边扩展,如果可以扩展则扩展。
猜的,具体好像证明我也没想明白,好像是因为他一开始就是有序的??

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int mod = 1e9 + 7;
vector<pair<int, int>> a;
int L[N];
int n;
int solve(vector<pair<int, int>> a) {
    if(a.size()==1) return 1;
    a[0].first -= L[0];
    int cnt = 1;
    for (int i = 1; i < n - 1; i++) {
        if (a[i].first - L[i] > a[i - 1].second) {
            a[i].first -= L[i];
            cnt++;
            continue;
        }
        if (a[i].second + L[i] < a[i + 1].first) {
            a[i].second += L[i];
            cnt++;
            continue;
        }
    }
    a[n - 1].second += L[n - 1];
    cnt++;
    return cnt;
}

signed main() {
    cin >> n;

    for (int i = 0; i < n; i++) {
        int x;
        cin >> x >> L[i];
        a.push_back(make_pair(x, x));
    }
    cout<<solve(a)<<endl;
    return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

万伏小太阳

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

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

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

打赏作者

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

抵扣说明:

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

余额充值