ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

牛客小白月赛55 A-E

2022-08-20 01:32:48  阅读:148  来源: 互联网

标签:cnt 55 至子 namespace long 牛客 int 小白月赛 include


牛客小白月赛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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有