首页 > 其他分享 >牛客周赛 Round 44

牛客周赛 Round 44

时间:2024-07-01 21:19:56浏览次数:1  
标签:std int 44 cin long 牛客 vector Round define

A题

每三张删除一张,n / 3就是答案

点击查看代码
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    int n;
    std::cin >> n;
    std::cout << n / 3 << '\n';
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

B题

一个序列最大值和最大公约数相等 等价于 这个序列的所有数都相等
序列是可以不连续的,所以找到出现次数最多的数就行

点击查看代码
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    int n;
    std::cin >> n;
    std::map<int, int> mp;
    int ans = 0;
    for (int i = 0; i < n; i ++) {
        int x;
        std::cin >> x;
        mp[x] ++;
        ans = std::max(ans, mp[x]);
    }
    std::cout << ans << '\n';
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

C题

倒着对字符串进行操作
把每一位都变成0
注意一下进位即可
进位会影响后面的数位

点击查看代码
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    std::string s;
    std::cin >> s;
    int ans = 0;
    std::reverse(all(s));
    bool ok = false;
    for (int i = 0; i < s.size() - 1; i ++) {
        int x  = s[i] - '0';
        if (ok) {
            x ++;
            x %= 10;
            ans += (10 - x) % 10;
        }
        else {
            if (x == 0) {
                continue;
            }
            else {
                ans += 10 - x;
                ok = true;
            }
        }
    }
    std::cout << ans << '\n';
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    std::cin >> T;
    while (T --) solve();
    return 0;
}

D题

记录一下每一个数的因数个数
因为因子个数不会超过100
所以可以对每种因子个数进行前缀和操作
然后再进行常数查询就可以了

点击查看代码
#include<bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    int n, q;
    std::cin >> n >> q;
    std::vector<int> a(n + 1);
    for (int i = 1; i <= n; i ++) {
        std::cin >> a[i];
    }
    auto ct = [&](int x) -> int{
        int cnt = 0;
        for (int i = 1; i <= x / i; i ++) {
            if (x % i == 0) {
                cnt ++;
                if (x / i != i) {
                    cnt ++;
                }
            }
        }
        return cnt;
    };
    std::vector<std::vector<int>> sum(201, std::vector<int> (n + 1));
    for (int i = 1; i <= n; i ++) {
        int cnt = ct(a[i]);
        sum[cnt][i] += 1;
    }
    for (int i = 1; i <= 200; i ++) {
        for (int j = 1; j <= n; j ++) {
            sum[i][j] += sum[i][j - 1];
        }
    }
    auto query = [&](int l, int r) -> int {
       int cnt = 0;
       for (int i = 1; i <= 200; i ++) {
           int x = sum[i][r] - sum[i][l - 1];
           cnt += x * (x - 1) / 2;
       }
       return cnt;
    }; 
    while (q --) {
        int l, r;
        std::cin >> l >> r;
        std::cout << query(l, r) << '\n';
    }
}
signed main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

E题

先特判n < 8无解
让前n - 4项等于i + 4
n为奇数时,最后四个可以构造为2 1 4 3
n为偶数时,最后四个可以构造为1 2 3 4

点击查看代码
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    int n;
    std::cin >> n;
    if (n < 8) {
        std::cout << -1 << '\n';
    }
    else {
        for (int i = 1; i <= n - 4; i ++) {
            std::cout << i + 4 << " ";
        }
        if (n & 1) {
            std::cout << "2 1 4 3\n";
        }
        else {
            std::cout << "1 2 3 4\n";
        }
    }
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

F题

对于基环树,有且只有一个环
所以1~n的路径最多只有2条
知道这个结论后,直接dfs即可

点击查看代码
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using i64 = long long;
using pii = std::pair<int, int>;
template<typename T>
std::vector<T> read(T& n)
{
    std::vector<T> a(n);
    for (auto& i : a) std::cin >> i;
    return a;
}
void solve()
{
    int n;
    std::cin >> n;
    std::vector<std::vector<pii>> adj(n + 1);
    std::vector<int> vis(n + 1), f(n + 1, 1e9);
    for (int i = 1; i <= n; i ++) {
    	int u, v;
    	std::cin >> u >> v;
    	adj[u].push_back({v, i});
    	adj[v].push_back({u, i});
    }
    auto dfs = [&](auto self, int u, int dep) -> void {
    	if (u == n) {
            for (int i = 1; i <= n; i ++) {
                if (!vis[i]) {
                    f[i] = std::min(f[i], dep);
                }
            }
            return;
        }
        for (auto [v, id] : adj[u]) {
            if (!vis[id]) {
                vis[id] = 1;
                self(self, v, dep + 1);
                vis[id] = 0;
            }
        }
    };
    dfs(dfs, 1, 0);
    for (int i = 1; i <= n; i ++) {
    	if (f[i] > 1e6) {
    		f[i] = -1;
    	}
    	std::cout << f[i] << '\n';
    }
}
int main()
{
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int T = 1;
    //std::cin >> T;
    while (T --) solve();
    return 0;
}

标签:std,int,44,cin,long,牛客,vector,Round,define
From: https://www.cnblogs.com/KXDdesu/p/18278869

相关文章

  • Educational Codeforces Round 167 (Rated for Div. 2) A-D
    A.CatchtheCoin题意:在一个二维坐标系上有一个硬币每秒y轴坐标减一,而你每秒可以向旁边八个方向移动,问你有没有一个时刻你会和硬币重叠。思路:注意到在y小于-2时,我们无论如何都追不到硬币,而其他时候我们可以采取向左下或者右下的策略来保持和硬币y轴下落同步移动的时候接近......
  • EPIC Institute of Technology Round Summer 2024 (Div. 1 + Div. 2)
    Preface沟槽的又掉分了,难得凑齐了五个人打LOL结果只玩了两把就去打这场CF了,早知道继续玩了这场经典开局不顺,C想了一堆假做法到30min的时候才出,D题上来就莽一个贪心然后爆WA两发后还不知道错哪了,卡到90min的时候心态小崩滚去看了眼E马上秒了后回来发现D是个很一眼的DP,写完后就只......
  • 牛客周赛 Round 49 (D~F)
    嘤嘤不想求异或喵think:首先l和r的范围有1e18,我们能要到要么是二分(但这题显然和二分无关),所以我们尝试打表找规律.打表发现x是4的倍数,1~x的异或和应该是x,同理其他也是有规律的.#include<bits/stdc++.h>#definefifirst#definesesecond#defineintlonglongusin......
  • Codeforces Round 918 G. Bicycles (二维最短路)
    G.Bicycles题意:在一个无向图里你要从1点到达n点,每条路的路径长度是该路的权值乘于你当前的慢度因子。而在每个点上我们都有一个慢度因子可以进行更换,问你到达n点所需要的最短时间。思路:我们很容易想到每次遇到更小的慢度因子我们就要更换,但因为存在你先去绕远路拿更小的慢......
  • 阅读笔记《GB/T28449-2018信息安全技术网络安全等级保护测评过程指南》
    方案编制:测评对象确定、测评指标确定、测评内容确定、工具测试方法确定、测评指导书开发、测评方案编制对每项活动均给出相应的工作流程、主要任务、输出文档及活动中的相关方的职责的规定,每项工作任务均有相应的输入、任务描述和输出产品测评风险:影响系统正常运行、感信息泄露......
  • Codeforces Round 894 (Div. 3) A-E cd 894 div3
    A.GiftCarpet每道题都是伸缩代码框有ac代码请不要漏掉--------------------------题解-----------------------------按先行便然后列再变循环设置jud每满足一个条件就让jud++只有jud==相应值的时候才让其++点击查看代码#include<bits/stdc++.h>usingnamespacestd;ch......
  • Public Round #13 题解
    旋转序列来源:IzbornePripreme2022(CroatianIOI/CEOITeamSelection)Day1,ProblemBhttps://qoj.ac/contest/956/problem/4326两个串之间\(1\)匹配的次数总和为\(k\timesl\),并且共有\(n\)次匹配。于是答案的上界为\(k\timesl\)个球放进\(n\)个盒子,最小化......
  • 牛客周赛 Round 49
    A题按题目输出即可#include<bits/stdc++.h>#defineall(x)(x).begin(),(x).end()#definefifirst#definesesecond#definelowbit(x)(x)&(-x)usingi64=longlong;usingpii=std::pair<int,int>;voidsolve(){i64a,b;std::cin>......
  • 《Programming from the Ground Up》阅读笔记:p1-p18
    《ProgrammingfromtheGroundUp》学习第1天,p1-18总结,总计18页。一、技术总结1.fetch-executecyclep9,TheCPUreadsininstructionsfrommemoryoneatatimeandexecutesthem.Thisisknownasthefetch-executecycle。2.general-purposevsspecial-purpose(......
  • 牛客周赛49
    比赛链接:牛客周赛49赛时感受A思路    代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglongconstintN=1e5+10;intmain(){lla,b;cin>>a>>b;cout<<a-b*11<<endl;return0;}B思路......