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

牛客小白月赛55 A-E

时间:2022-08-20 00:55:29浏览次数:76  
标签: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
From: https://www.cnblogs.com/CTing/p/16606997.html

相关文章

  • C++primer练习13.55-58
    练习13.55为你的StrBlob添加一个右值引用版本的Push_backvoidStrBlob::push_back(string&&s){data->push_back(std::move(s));}练习13.56如果sorted定义如下,会发生......
  • "蔚来杯"2022牛客暑期多校训练营9 G Magic Spells
    原题链接一开始manacher+单哈希wa,样例通过率97%,应该是卡了一手int_64自然溢出换成manacher+双哈希过了#include<bits/stdc++.h>usingnamespacestd;#definefr......
  • 2022牛客暑假第七场C、F、J、K
    C-ConstructiveProblemsNeverDie_"蔚来杯"2022牛客暑期多校训练营7(nowcoder.com)容易知道,只要A中的数不是全部相同,就一定有解。我们思考如何构造:如果A中的数是一......
  • "蔚来杯"2022牛客暑期多校训练营7 题解
    C.ConstructiveProblemsNeverDie对于出现次数大于1的数字,用出现次数为0的数字填充。剩下的数字一定两两互不相同,对这些数循环移位,最后进行判断即可。#include<bits/......
  • 55
    basin盆地     music音乐himself他自己here这里internal内部的pig猪conform符合noise噪音steep陡峭的something某物opposite对面的......
  • CF559C Gerald and Giant Chess
    GeraldandGiantChessCF599C(Luogu)题面翻译给定一个H*W的棋盘,棋盘上只有N个格子是黑色的,其他格子都是白色的。在棋盘左上角有一个卒,每一步可以向右或者向下移动一格......
  • POJ2955 Brackets
    题目链接题目DescriptionWegivethefollowinginductivedefinitionofa“regularbrackets”sequence:theemptysequenceisaregularbracketssequence,ifs......
  • "蔚来杯"2022牛客暑期多校训练营7
    比赛链接:https://ac.nowcoder.com/acm/contest/33192C.ConstructiveProblemsNeverDie题意:已知序列\(a\),找出一个排列\(p\)使得\(a_i!=p_i(1<=i<=n)\)。......
  • CF559E Gerald and Path(DP)
    CF559EGeraldandPath设\(dp(i,p)\)表示完成前\(i\)条线段的覆盖,最右端位于\(p\)点的最大收益。转移?向下一条线段转移时加上他们中间的距离?发现这样没有办法统计......
  • SP1557 GSS2 - Can you answer these queries II(离线 线段树)
    SP1557GSS2-CanyouanswerthesequeriesII\(\bigstar\texttt{Hint}\):遇到去重的问题,我们通常考虑离线询问后处理。可以枚举右端点,将询问存储在右端点,考虑用数据结......