首页 > 编程语言 >牛客周赛 Round 46 题解 C++

牛客周赛 Round 46 题解 C++

时间:2024-06-10 17:30:10浏览次数:17  
标签:周赛 typedef 46 题解 ll cin long int include

目录

 A 乐奈吃冰

B 素世喝茶

C 爱音开灯

D 小灯做题

E 立希喂猫

F 祥子拆团


 A 乐奈吃冰

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;

const int N = 3e5 + 10,M = 1e9 + 7;

int n,m;
int a[N],b[N];
bool st[N];
ll cnt;

void solve()
{
    cin >> n >> m;
    if(n == 1)
    {
        cout << 1;
        return ;
    }
    if(m > n / 2)
    {
        cout << n / 2 + n;
    }
    else
    {
        cout << n + m;
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t --)
    {
        solve();
    }
    return 0;
}

素世喝茶

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;

const int N = 3e5 + 10,M = 1e9 + 7;

int n,m;
int a[N];
bool st[N];
ll cnt;

void solve()
{
    cin >> n >> m;
    int mx = 0;
    for(int i = 1; i <= n; i ++)
    {
        int x;
        cin >> x;
        if(i == m) continue;
        if(x > mx)
        {
            mx = x;
            cnt = 1;
        }
        else if(x == mx){
            cnt ++;
        }
    }
    cout << cnt;
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t --)
    {
        solve();
    }
    return 0;
}

爱音开灯

#include <iostream>
#include <cmath>

using namespace std;

void solve() {
    long long n, m;
    cin >> n >> m;
    long long cnt = 0;
    for (long long i = 1; i * i <= m; i++) {
        if(m % i == 0)
        {
            if(i<=n) cnt++;
            if(m/i!=i&&m/i<=n) cnt++;
        }
    }
    if (cnt % 2 == 1) {
        cout << "ON";
    } else {
        cout << "OFF";
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

小灯做题

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;

const int N = 3e5 + 10,M = 1e9 + 7;

ll n,m;
int a[N];
bool st[N];
ll cnt;
int k,res;

int mex(int a,int b){
    if(a + b == 1)
    {
        return 2;
    }
    else
    {
        if(a == 0 || b == 0)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
}

void dfs(int a,int b,int c,int sum){
    
    if(sum > 3 || a == k || b == k || c == k){
        res=min(res,sum);
        return ;
    }
    
    dfs(a,b,mex(a,b),sum+1);
    dfs(a,mex(a,c),c,sum+1);
    dfs(mex(b,c),b,c,sum+1);
}

void solve()
{
    cin >> n;
    while(n --)
    {
        int a,b,c;
        cin >> a >> b >> c >> k;
        res = N;
        if(a == k || b == k || c == k)
        {
            cout << 0 << "\n";
            continue;
        }
        if(k >= 3)
        {
            cout << -1 << "\n";
            continue;
        }
        dfs(a,b,c,0);
        cout << res << "\n";
    }

}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t --)
    {
        solve();
    }
    return 0;
}

立希喂猫

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#include <queue>
#include <set>
#include <vector>
#include <unordered_map>

using namespace std;

typedef pair<int,int> PII;
typedef long long ll;
#define x first
#define y second

const int N = 3e5 + 10,M = 1e9 + 7;

ll n,m;
ll s1[N],s2[N];
ll c[N];
bool st[N];
ll cnt;

PII a[N];

void solve()
{
    cin >> n;

    for(int i = 1; i <= n ;i ++)
    {
        cin >> a[i].y;
    }

    for(int i = 1; i <= n ;i ++)
    {
        cin >> a[i].x;
    }

    sort(a+1,a+1+n);

    for(int i = 1; i <= n ; i ++)
    {
        s1[i] += s1[i-1] + a[i].y * a[i].x;
        s2[i] += s2[i-1] + a[i].y;
    }

    cin >> m;

    while(m --)
    {
        int t;
        cin >> t;

        ll res = 0;
        pair<int,int> p(t,0);
        int id_1 = upper_bound(a + 1,a+ n + 1,p) - a;
        res += s1[id_1 - 1];
        res += (s2[n] - s2[id_1 - 1]) * t; 
        cout << res << "\n";
    }
    return ;
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    while(t --)
    {
        solve();
    }
    return 0;
}

祥子拆团

没代码思路,后面补

标签:周赛,typedef,46,题解,ll,cin,long,int,include
From: https://blog.csdn.net/2202_75334392/article/details/139577823

相关文章

  • 斜率优化DP简单总结&&“土地购买”题解
    今天刚刷完了斜率优化DP,简单从头回顾一下。\[首先,能写出DP方程应该是最重要的,毕竟斜率只是用来优化的\]那么一个DP方程能用斜率优化,具备一种形式:\[f[i]+s1[i]+A[i]*B[j]=f[j]+s2[j]\]其中,f[i]表示所求值,(s1[i]、A[i])与(s2[j]、B[j])分别表示只与i或j有关的一个表达式(可以是只有常......
  • Codeforces Round 837题解(A、B)
    A.HossamandCombinatorics\(|a_i-a_j|\)最大的就是最大值和最小值,注意要开longlong。intn;inta[N];voidsolve(){cin>>n;intmin_v=INF,max_v=0;for(inti=1;i<=n;i++){cin>>a[i];min_v=min(min_v,a[i......
  • CF1970F1 Playing Quidditch (Easy) 题解
    一道大模拟题。这道题可以用一个 map 记录球员及鬼飞球当时的坐标,用一个数组 a 记录是否有人进球,用另一个数组 b 记录每位球员是否有鬼飞球。当球员抓住鬼飞球后,鬼飞球跟着这个球员移动,直到这个球员投球。话不多说,直接上代码。MyCode:#include<bits/stdc++.h>#de......
  • 【题解】 [CSP-J 2019] 纪念品
    题目描述题目大意在\(T\)天内,有\(n\)种纪念品和初始的\(m\)元。可以得到每天每种纪念品的价格。每一天可以以当日价格买卖纪念品。特别的,当天卖出得到的钱可以当天买入,当日买入的纪念品也可以当日卖出。当然可以一直持有。但是,\(T\)天过后,手上不可以持有纪念品。思路......
  • 【2024最新华为OD-C/D卷试题汇总】[支持在线评测] 机场航班调度程序(100分) - 三语言A
    ......
  • 【2024最新华为OD-C/D卷试题汇总】[支持在线评测] 最富裕的小家庭(100分) - 三语言AC
    ......
  • P7690 [CEOI2002] A decorative fence 题解
    cnblogs如果只是询问方案数,是P2467[SDOI2010]地精部落这道题,设\(f_{i,j,1/0}\)表示以\(j\)个数中从小到大的第\(i\)个数处于高/低位开头的方案数。显然有\[\begin{aligned}\begin{cases}f_{i,j,1}=\sum_{k=1}^{i-1}f_{k,j-1,0}\\f_{i,j,0}=\sum_{k=i}......
  • Kali Linux 2024.2 发布 (t64, GNOME 46 & Community Packages) - 领先的渗透测试发行
    KaliLinux2024.2发布(t64,GNOME46&CommunityPackages)-领先的渗透测试发行版ThemostadvancedPenetrationTestingDistribution请访问原文链接:https://sysin.org/blog/kali-linux/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgKaliLinux2024.2已......
  • livedream 周赛 pdf 合集
    第16场:http://obj.dreamoj-test.gonoi.com.cn/prod/exam/209/209/2.pdf?e=1717202238&token=C3jZ5bjv2FEUhrgS2AJ_8hwVpnRD8H-L48ONR4bV:wnFzL-1uIlQmejxCfeDTcHd1zgk=,密码XV8UF2。第17场:http://obj.dreamoj-test.gonoi.com.cn/prod/exam/220/220/1.pdf?e=1717938817&a......
  • 46.django - 多语言配置
    1.Django多语言基础知识多语言站点可以让不同语言的用户更好地使用和理解网站内容,提升用户体验和覆盖范围。为了实现多语言功能,我们将使用Django内置的国际化和本地化支持。我收集了一些知识点整理在这一部分,感兴趣的可以看看。直接跳过此部分也行。也可以看看官方文档:翻译......