牛客周赛 Round 47

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四个数,考虑全部组合数量为4n
对于竖直对称可以发现只能放0,2,5,8四个数,因为竖直对称,因此只要考虑前n2个位置如何摆放,方案数为4n2。对于n为奇数,可以发现中间只能摆放0,8,因此方案数需要再乘上2。
最后减去两种方案的重合数2n+12即可。

代码实现

#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';
}
posted @   sleeeeeping  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
  1. 1 吹梦到西洲 恋恋故人难,黄诗扶,妖扬
  2. 2 敢归云间宿 三无Marblue
敢归云间宿 - 三无Marblue
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

敢归云间宿 - 三无Marblue

词:怀袖

曲:KBShinya

编曲:向往

策划:杨颜

监制:似雨若离RainJaded/杨颜

吉他:大牛

混音:三无Marblue

和声:雾敛

母带:张锦亮

映像:似雨若离RainJaded

美术:阿尼鸭Any-a/乙配/雨谷/今风/米可/Eluan

题字:长安

酒 泼去群山眉头

酒 泼去群山眉头

月 悬在人世沧流

空杯如行舟 浪荡醉梦里走

心 生自混沌尽头

心 生自混沌尽头

对 天地自斟自酬

诗随我 遍历春秋

行流水 走笔形生意动

见珠玉 淙淙落纸成诵

拾得浮名有几声 云深处 却空空

耳畔丝竹 清商如雾

谈笑间 却是心兵穷途

飞觞醉月无归宿 便是孤独

不如就化身为风

卷狂沙 侵天幕

吹醒那 泉下望乡 的战骨

昨日边关犹灯火

眼前血海翻覆

千万人跌落青史 隔世号呼

于是沸血重剑共赴

斩以雷霆之怒

肩背相抵破阵开路

万古同歌哭

纵他春风不度 悲欢蚀骨

此去宁作吾

挣过命途 才敢写荣枯

望 云际群龙回首

望 云际群龙回首

任 飘蓬争逐身后

叹冥顽之俦 好景尽付恩仇

收 江声随酒入喉

收 江声随酒入喉

来 提笔御风同游

不觉已 换了春秋

真亦假 泼墨腾烟沉陆

有还无 蝶影纷堕幻目

我与天地周旋久

写尽梦 便成梦

夜雨浇熄 往事残烛

生死间 谁尽兴谁辜负

管他醒来归何处 心生万物

也曾对电光火雨

抛酒樽 镇天枢

护住了 人间多少 朝与暮

烧尽了阴云冥府

烧尽了阴云冥府

且看星斗尽出

浩荡荡尘埃野马 忘怀命数

于是信步鸿蒙之轻

也领苍生之重

与诗与剑颠倒与共

沉眠斜阳中

纵他世事汹涌 万类争渡

此去宁作吾

醉得糊涂 才梦得清楚

潮水 带着叹息轻抚

潮水 带着叹息轻抚

像光阴 漫过大地上幽微草木

有情世 见众生明灭往复

天生自在 何必回顾

晦暗中双掌一拊

立此身 照前路

与某个 阔别的我 决胜负

渺渺兮身外无物

无喜无悲无怖

不过是大梦一场 各自沉浮

于是纵横万相穷通

也守心底灵通

合眼识得星沉地动

也岿然不动

敢令岁月乌有 逍遥长驻

敢归云间宿

遥祝远行人 有道不孤

点击右上角即可分享
微信分享提示