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

牛客周赛 Round 47

时间:2024-06-18 11:53:49浏览次数:5  
标签:std constexpr int 47 cin 牛客 res MInt Round

A、小红的葫芦

水一篇

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n = 5;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    std::sort(a.begin(), a.end());
    debug(a);
    bool ok = false;
    if (a[0] == a[1] && a[1] == a[2] && a[2] != a[3] && a[3] == a[4]) {
        ok = true;
    }
    std::reverse(a.begin(), a.end());
    if (a[0] == a[1] && a[1] == a[2] && a[2] != a[3] && a[3] == a[4]) {
        ok = true;
    }
    std::cout << (ok ? "YES" : "NO") << "\n";
}

B、茉茉的密码

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    std::cin >> n;
    std::vector<std::string> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    for (char c = 'a'; c <= 'z'; ++c) {
        bool ok = true;
        for (int i = 0; i < n; ++i) {
            ok &= a[i].find(c) != std::string::npos;
        }
        if (ok) {
            std::cout << c << '\n';
            return 0;
        }
    }
}

C、苗苗的气球

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    auto b = a;
    std::sort(a.begin(), a.end());
    int sum = std::accumulate(a.begin(), a.end(), 0LL);
    int ans = 0;
    if (n == 2) {
        ans += (b[0] > b[1]) + (b[0] < b[1]); 
    } else {
        if (sum > 2LL * a[n - 1]) {
            for (int i = 0; i < n; ++i) {
                ans += b[i] > (sum % 2 == 0);
            }
        } else {
            for (int i = 0; i < n; ++i) {
                ans += b[i] == a[n - 1];
            }
        }
    }
    std::cout << ans << '\n';
}

D、萌萌的好数

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    #define int long long
    int tt;
    for (std::cin >> tt; tt--;) {   
        int n;
        std::cin >> n;
        auto check = [&](int x) {
            x -= 3;
            int ans = (x + 3) / 3 + (x / 10 - x / 10 / 3);
            return x + 3 - ans >= n;
        };
        int l = 1, r = 1e18;
        while (l < r) {
            int mid = l + r >> 1;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        std::cout << r << '\n';
    }
}

E、 茜茜的计算器

分析

水平和竖直对称分开考虑。
对于水平对称可以发现只能放\(0, 1, 3, 8\)四个数,考虑全部组合数量为\(4 ^ n\)。
对于竖直对称可以发现只能放\(0, 2, 5, 8\)四个数,因为竖直对称,因此只要考虑前\(\frac{n}{2}\)个位置如何摆放,方案数为\(4^{\frac{n}{2}}\)。对于n为奇数,可以发现中间只能摆放\(0, 8\),因此方案数需要再乘上2。
最后减去两种方案的重合数\(2^{\frac{n + 1}{2}}\)即可。

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T>
constexpr T power(T a, long long b) {
    T res = 1;
    for (; b; b /= 2, a *= a)
        if (b % 2) res *= a;
    return res;
}
template <int P>
struct MInt {
    int x;
    constexpr MInt() : x{} {}
    constexpr MInt(long long x) : x{norm(x % P)} {}
    constexpr int norm(int x) const {
        if (x < 0) x += P;
        if (x >= P) x -= P;
        return x;
    }
    constexpr int val() const { return x; }
    explicit constexpr operator int() const { return x; }
    constexpr MInt operator-() const {
        MInt res;
        res.x = norm(P - x);
        return res;
    }
    constexpr MInt inv() const {
        assert(x != 0);
        return power(*this, P - 2);
    }
    constexpr MInt &operator*=(MInt rhs) {
        x = 1ll * x * rhs.x % P;
        return *this;
    }
    constexpr MInt &operator+=(MInt rhs) {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr MInt &operator-=(MInt rhs) {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr MInt &operator/=(MInt rhs) { return *this *= rhs.inv(); }
    friend constexpr MInt operator*(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr MInt operator+(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr MInt operator-(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr MInt operator/(MInt lhs, MInt rhs) {
        MInt res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, MInt &a) {
        long long v;
        is >> v;
        a = MInt(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); }
    friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); }
    friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); }
};

template <int V, int P>
constexpr MInt<P> CInv = MInt<P>(V).inv();

// constexpr int P = 998244353;
constexpr int P = 1e9 + 7;
using Z = MInt<P>;
int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n ;
    std::cin >> n;
    Z lr = power(Z(4), n / 2), ud = power(Z(4), n);
    Z cocide = power(Z(2), (n + 1) / 2);
    if (n & 1) {
        lr *= 2;
    }
    std::cout << lr + ud - cocide << '\n';
}

F、花花的地图

代码实现

#include <bits/stdc++.h>

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int n, m;
    std::cin >> n >> m;
    std::vector<std::string> g(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> g[i];
    }
    std::vector<int> C(m);
    for (int i = 0; i < m; ++i) {
        std::cin >> C[i];
    }
    std::vector dist(n, std::vector<int>(m, 1e9));
    std::vector<std::vector<bool>> vis(n, std::vector<bool>(m));
    std::priority_queue<std::array<int, 3>, std::vector<std::array<int, 3>>, std::greater<>> q;
    q.push({0, 0, 0});
    dist[0][0] = 0;
    while (size(q)) {
        auto [dis, x, y] = q.top();
        q.pop();
        if (x == n - 1 && y == m - 1) {
            break;
        }
        vis[x][y] = true;
        for (auto [fx, fy] : {std::pair{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}}) {
            if (fx >= 0 && fx < n && fy >= 0 && fy < m && !vis[fx][fy]) {
                if (g[fx][fy] == '.') {
                    if (dist[fx][fy] <= dis) continue;
                    dist[fx][fy] = dis;
                    q.push({dis, fx, fy});
                } else {
                    for (int fx = 0; fx < n; ++fx) {
                        if (dist[fx][fy] <= dis + C[fy]) continue;
                        dist[fx][fy] = dis + C[fy];
                        q.push({dist[fx][fy], fx, fy});
                    }
                }
            }
        }
    }
    std::cout << dist[n - 1][m - 1] << '\n';
}

标签:std,constexpr,int,47,cin,牛客,res,MInt,Round
From: https://www.cnblogs.com/sleeeeeping/p/18254027

相关文章

  • Codeforces Round 952 (Div. 4)
    知识点模块1.一个正方体x,y,z里面可以放多少个边长为a,b,c的长方体ans=(x-a+1)*(y-b+1)*(z-c+1)题解模块A.CreatingWords交换两个字母的首字母即可swap实现即可点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongtypedefpair<int,int>......
  • 47.JavaScript基础【五】
    【一】什么是jQuery1)概述是一个轻量的、兼容多浏览器的JavaScript的第三方库其内部封装了JS代码、能通过更少的代码操作DOM对象提高了代码效率、简化了代码量2)优势轻量级的JS框架丰富的DOM选择器链式表达式事件、样式、动画支持Ajax操作支持跨浏览器兼容插件扩展开......
  • [NSSRound#3 Team]jump_by_jump
    Problem:[NSSRound#3Team]jump_by_jump目录思路总结思路jz,jnz经典的花指令,解题思路:将call给硬编码,nop,修复所有黄色字段,在重新生成函数可以解决D-->转换为硬编码此处转化为0E8h了C-->修复汇编语言一点一点修复即可P-->重新生成函数在此处main直接p生成函数即可......
  • Codeforces Round 953 (Div. 2) A - F
    A编号为\(n\)的一定选,第二叠书在\(1\simn-1\)选最大的。voidsolve(){ cin>>n; for(inti=1;i<=n;++i){ cin>>a[i]; } intans=a[n]; intx=0; for(inti=1;i<n;++i){ x=max(x,a[i]); } cout<<ans+x<&......
  • Codeforces Round 953 Div.2 F 题解
    连通块计数的一种常见思路是钦定代表元,但发现这题的连边方式并不好指定一个代表元,那么只能尝试优化建图。我们尝试观察一下连边的情况,通过手玩样例获得一些几何直观的感受:345534453这个样例也许比较小,不过你真的把边画出来就会发现:连边形如\(2n-1\)条完整的斜线,中间......
  • Codeforces Round 953 (Div. 2)(A~D题解)
    这次比赛是我最顺利的一次比赛,也是成功在中途打进前1500,写完第三道题的时候也是保持在1600左右,但是后面就啥都不会了,还吃了点罚时,虽说如此也算是看到进步了,D题学长说很简单,但是我当时分析错了,出了一点小问题,不然最后也能定格在2000左右,下次加油。A.AliceandBooks 题意:......
  • 牛客周赛47 (待补F和思路)
    比赛链接:牛客周赛47赛时感受    又是一场思维题,应该只有EF有点算法,E需要使用快速幂和取余,F做不出,C卡了我一下,D写完了,E不写完一半又回来看C才做掉的,E也卡了很久虽然鸽巢原理想到了,但是没想到被卡在取余问题上,一开始没想出来,去做F然后做了半个小时发现做不掉,又回来在E上......
  • 牛客周赛 Round 47
    时刻多日没打竟然退步了 A.小红的葫芦思路:五个元素三个相同另外两个相同可以通过数组排序写也可以map等等方法很多Code:#include<bits/stdc++.h>usingnamespacestd;map<int,int>mp;intmain(){ios::sync_with_stdio(false);cin.tie(0);......
  • Codeforces Round 952 (Div. 4) G. D-Function(思维)
    Problem-G-Codeforces思维题,推出公式用等比数列求和做一下。1#defineIOstd::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)2#definebug2(x,y)cout<<#x<<"is"<<x<<""<<#y<<"is"<<y<<end......
  • GH2747高温合金进口板弹性模量与蠕变性能
    通过对GH2747高温合金的材料特性和性能进行详细的描述和分析,提供了该合金在高温环境下的弹性模量和蠕变性能的关键参数,为其在航空航天、能源等领域的应用提供了重要参考。弹性模量(ElasticModulus):GH2747高温合金的弹性模量是衡量其在受力作用下回复原状能力的重要参数之一。......