“蔚来杯“2022牛客暑期多校训练营1 A、D、G、I

A

区间合并

AC代码:

#include <iostream>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using LL = long long;
//head



int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<pair<LL, LL>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        LL tmp = a[i].first;
        a[i].first = a[i].first - a[i].second;
        a[i].second = tmp + a[i].second;
    }
    sort(a.begin(), a.end(), [&](pair<LL, LL> a, pair<LL, LL> b) {
        if (a.first != b.first) {
            return a.first < b.first;
        }
        return a.second < b.second;
    });
    LL ans = 0;
    LL r = a[0].second;
    for (int i = 1; i < n; i++) {
        if (a[i].first > r) {
            ans += a[i].first - r;
            r = a[i].second;
        }
        else {
            r = max(r, a[i].second);
        }
    }
    cout << ans << '\n';

    return 0;
}

D

数学几何题

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const double PI = acos(-1.0);

void Solve() {
    double r, xq, yq, d;
    cin >> r >> xq >> yq >> d;
    double zhouchang = 2 * PI * r;
    double len = sqrt(xq * xq + yq * yq);
    double c = len + d;
    double x = len - d;
    double now1 = acos(c / r);
    double now2 = acos(x / r);
    double now3 = now1 > now2 ? now1 - now2 : now2 - now1;
    cout << fixed << setprecision(9) << zhouchang * now3 / PI / 2 << '\n';
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        Solve();
    }

    return 0;
}

G

AC代码:

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



int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    cin >> s;
    int len = s.size();
        int cnt = 0;
        for (int i = 0; i < len; i++) {
            if (s[i] == '9') {
                cnt++;
            }
            else {
                break;
            }
        }
        if (cnt >= len - 1) {
            cout << s <<'\n';
        }
        else {
            for (int i = 0; i < len - 1; i++) {
                cout << 9;
            }
            cout << '\n';
        }

    return 0;
}

I

概率期望DP+逆元

AC代码:

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL mod = 1e9 + 7;
LL dp[150][30];
LL qp(LL a, LL b, LL res) {
    for (; b; b >>= 1, a = a * a % mod) {
        if (b & 1) {
            res = res * a % mod;
        }
    }
    return res % mod;
}
LL inv(LL x, LL y) {
    return qp(x, mod - 2, y);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//1.没摸到 2.四张全摸到
    for (int i = 1; i <= 4 * 34 - 13; i++) {
        for (int j = 1; j <= 13; j++) {
            if (i < 3 * j) {
                continue;
            }
            LL iinv = inv(i, 3 * j);
            if (j == 1) {
                dp[i][j] = (1 + dp[i - 1][j] * (1 + mod - iinv)) % mod;
            }
            else {
                dp[i][j] = (1 + dp[i - 1][j] * (1 + mod - iinv) + dp[i - 1][j - 2] * iinv) % mod;
            }
        }
    }
    int T;
    cin >> T;
    for (int j = 1; j <= T; j++) {
        string s;
        cin >> s;
        map<string, int> mp;
        for (int i = 0; i < 26; i += 2) {
            string x = "";
            x += s[i];
            x += s[i + 1];
            mp[x]++;
        }
        int ans = 0;
        for (auto it : mp) {
            if (it.second == 2) {
                ans++;
            }
        }
        cout << "Case #" << j << ": " << dp[4 * 34 - 13][13 - 2 * ans] << '\n';
    }

    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值