牛客等级之题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;
}

牛客等级之题N2(8.11场)

数数

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int p = 998244353, maxn = 1e7+5;
int mul[maxn];
ll qpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = res*a%p;
        a = a*a%p;
        b >>= 1;
    }
    return res%p;
}
int main() {
    mul[0] = 1;
    for (int i = 1; i <= 10000000; ++i) {
        mul[i] = ll(mul[i-1])*i%p;
    }
    int t; cin >> t;
    while (t--) {
        ll n; cin >> n;
        ll sum = n*(n+1)/2 % p;
        cout << sum*sum%p << " " << qpow(mul[n],n+n) << endl;
    }
    return 0;
}

牛客等级之题N2(8.12场)

小w的a+b问题

#include <bits/stdc++.h>
using namespace std;
int main() {
    int c; cin >> c;
    if (c == -1) cout << "No solution" << endl;
    else {
        int a = 2147483647;
        cout << a << " " << c-a << endl;
    }
    return 0;
}

牛客等级之题N2(8.13场)

斐波那契

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll p = 1e9+7;
struct mat {
    ll a[2][2];
    mat() {
        memset(a,0,sizeof(a));
    }
};
mat mul(mat A, mat B) {
    mat C;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                C.a[i][j] = (C.a[i][j] + A.a[i][k]*B.a[k][j]%p)%p;
            }
        }
    }
    return C;
}
mat qpow(mat A, ll b) {
    mat res;
    for (int i = 0; i < 2; ++i) res.a[i][i] = 1;
    while (b) {
        if (b & 1) res = mul(res,A);
        A = mul(A,A);
        b >>= 1;
    }
    return res;
}
int main() {
    ll n; cin >> n;
    mat A;
    A.a[0][0] = 1, A.a[0][1] = 1;
    A.a[1][0] = 1, A.a[1][1] = 0;
    A = qpow(A,n-1);
    mat B;
    B.a[0][0] = 1, B.a[0][1] = 0;
    B.a[1][0] = 1, B.a[1][1] = 0;
    B = mul(A, B);
    cout << B.a[0][0]*B.a[1][0]%p << endl;
    return 0;
}

牛客等级之题N2(8.18场)

Audio

#include <bits/stdc++.h>
using namespace std;
double x[4], y[4];
int main() {
    for (int i = 1; i <= 3; ++i) {
        scanf("%lf%lf",&x[i],&y[i]);
    }
    double k1 = (x[2]-x[1])/(y[1]-y[2]);
    double k2 = (x[3]-x[1])/(y[1]-y[3]);
    double b1 = (y[1]+y[2])/2 - (x[1]+x[2])/2*k1;
    double b2 = (y[1]+y[3])/2 - (x[1]+x[3])/2*k2;
    x[0] = (b2-b1)/(k1-k2);
    y[0] = k1*x[0] + b1;
    printf("%.3lf %.3lf\n",x[0],y[0]);
    return 0;
}

牛客等级之题N2(8.19场)

牛妹和01串

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    int a = 0, b = 0, m = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '0') a++;
        else b++;
        if (a && b) {
            m++;
            a = b = 0;
        }
    }
    cout << m << endl;
    return 0;
}

牛客等级之题N2(8.20场)

爵士

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n; getchar();
        int num = 0;
        for (int i = 1; i <= n; ++i) {
            string s; getline(cin,s);
            if (s.find('2') != -1) num++;
        }
        printf("%.4f\n",double(num)/n);
    }
    return 0;
}
posted @ 2020-08-11 12:49  麻辣猪仔  阅读(174)  评论(0编辑  收藏  举报