其他分享
首页 > 其他分享> > 牛客小白月赛55 A-E

牛客小白月赛55 A-E

作者:互联网

牛客小白月赛55 A-E

https://ac.nowcoder.com/acm/contest/38630

F待补
解析啥的睡醒再补,先放个代码

A - 至至子的等差中项

#include <bits/stdc++.h>

using namespace std;

int main () {
    int a, b;
    cin >> a >> b;
    cout << 2*b-a;
}

B - 至至子的按位与

#include <bits/stdc++.h>
#define int long long

using namespace std;
int a, b;

void solve () {
    cin >> a >> b;
    int maxn = (1ll << 63) - 1ll;
    cout << maxn - (a ^ b) << endl;
}

signed main () {
    solve ();
}

C - 至至子的斐波那契

#include <bits/stdc++.h>
#define int long long

using namespace std;
vector <int> v;

void pre () {
    
    v.push_back (0), v.push_back (1), v.push_back (1);
    int x = 0;
    for (int i = 3; x <= 1e18; i++) {
        x = v[i-1] + v[i-2];
        v.push_back (x);
    }

    //for (auto i : v)    cout << i << ", ";
}

void solve () {
    int n, i;
    cin >> n;
    for (i = 1; ; i++) {
        if (v[i] >= n)  break;
    }
    if (v[i] - n >= n - v[i-1])  cout << i-1;
    else cout << i;
    cout << endl;
}

signed main () {
    pre ();
    int t;
    cin >> t;
    while (t --) {
        solve ();
    }
}

D - 至至子的鸿门宴

#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1e6 + 5;
int n, a[N];

signed main () {
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i] - i;
    }
    // b[1] = a[1];

    // for (int i = 1; i <= n; i++)    b[i] --, sum += b[i];
    //cout << sum << endl;
    if (sum % 2 == 0)   puts ("SSZ");
    else    puts ("ZZZ");

}

E - 至至子的长链剖分

#include <bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> pii;
const int N = 2e5 + 5;
int n;

void solve () {
    cin >> n;
    vector <int> cnt[n+1]; //pre cnt
    int maxn = 0, x;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        cnt[x].push_back (i);
        maxn = max (maxn, x);
    }

    // for (int i = 0; i <= n; i++) {
    //     if (cnt[i].size() == 0) continue;
    //     cout << "i= " << i << ", ";
    //     for (auto j : cnt[i])
    //         cout << j << ' ';
    //     cout << endl;
    // }

    if (n == 1) {
        if (x)    cout << -1 << endl;
        else    cout << 1 << endl;
        return ;
    }

    if (cnt[maxn].size() > 1 || cnt[0].size() == 0)  {
        cout << -1 << endl;
        return ;
    }

    vector <pii> ans;
    for (int i = 1; i <= maxn; i++) {
        if (cnt[i].size() == 0 || cnt[i].size() > cnt[i-1].size()) {
            cout << "-1\n";
            return ;
        }
        int cnt1 = cnt[i-1].size(), cnt2 = cnt[i].size();
        for (int j = 0; j < cnt2; j++)  ans.push_back ({cnt[i-1][j], cnt[i][j]});
        for (int j = cnt2; j < cnt1; j++)   ans.push_back ({cnt[i-1][j], cnt[i][0]});
    }

    cout << cnt[maxn][0] << endl;
    for (auto i : ans)  cout << i.first << ' ' << i.second << endl;

}

signed main () {
    int t;
    cin >> t;
    while (t --) {
        solve ();
    }
}

//h为几就在第几+1层(从下往上)
//相邻数字连一条边
//并且上层的个数一定要小于等于下层的

//之前是把所有的都连到一点上所以就错了
//上一层与下一层尽量相连,然后多的在统一连到一点

F - 至至子的公司排队

别急

标签:cnt,55,至子,namespace,long,牛客,int,小白月赛,include
来源: https://www.cnblogs.com/CTing/p/16606997.html