1. 程式人生 > 實用技巧 >牛客等級之題N2

牛客等級之題N2

目錄


牛客等級之題N2(8.3場)

等級之題N2

設大半圓的半徑為\(R\),左小半圓半徑為\(r\)
\(r = kR(0<k<1)\)
\(\pi R^2 - \pi k^2R^2 - \pi (R-kR)^2 = 2s\)
\(R^2(k-k^2)=\frac{s}{\pi}\)
\(k = \frac{1}{2}\)\(R^2\)最小

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int main() {
    double s;
    scanf("%lf",&s);
    printf("%.3lf\n",2*sqrt(s/pi));
    return 0;
}

牛客等級之題N2(8.4場)

拯救單身狗

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; cin >> t;
    while (t--) {
        unordered_map<int,int> mp;
        bool flag = true;
        int num;
        while (cin >> num && num) {
            mp[num]++;
        }
        for (unordered_map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it) {
            if (it->second & 1) {
                flag = false;
                break;
            }
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

牛客等級之題N2(8.5場)

做題

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; cin >> t;
    while (t--) {
        unordered_map<int,int> mp;
        bool flag = true;
        int num;
        while (cin >> num && num) {
            mp[num]++;
        }
        for (unordered_map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it) {
            if (it->second & 1) {
                flag = false;
                break;
            }
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

牛客等級之題N2(8.6場)

Rinne Loves Study

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
int row[maxn], col[maxn];
int main() {
    int n, m, T;
    cin >> n >> m >> T;
    for (int i = 1; i <= T; ++i) {
        int opt; cin >> opt;
        if (opt == 1) {
            int x; cin >> x;
            row[x] = i;
        }
        else {
            int y; cin >> y;
            col[y] = i;
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (j == 1) cout << max(row[i],col[j]);
            else cout << " " << max(row[i],col[j]);
        }
        cout << endl;
    }
    return 0;
}

牛客等級之題N2(8.10場)

小sun的假期

#include <bits/stdc++.h>
using namespace std;
struct node {
    int l, r;
};
vector<node> ve;
bool cmp(const node x, const node y) {
    return x.l < y.l;
}
int main() {
    int n, m; cin >> n >> m;
    while (m--) {
        int l, r; cin >> l >> r;
        ve.push_back(node{l,r});
    }
    sort(ve.begin(),ve.end(),cmp);
    
    int pos = 0, ans = 0, pre = 1;
    while (pos < ve.size()) {
        int l = ve[pos].l, r = ve[pos].r;
        pos++;
        while (pos < ve.size() && l <= ve[pos].l && ve[pos].l <= r) {
            r = max(r,ve[pos].r);
            pos++;
        }
        ans = max(ans,l-pre);
        pre = r+1;
    }
    ans = max(ans,n+1-pre);
    cout << ans << endl;
    return 0;
}