AcWing第 127 场周赛 - AcWing 5283. 牛棚入住+AcWing 5284. 构造矩阵 - 模拟+快速幂+数学

AcWing 5283. 牛棚入住

题目数据范围不大,直接暴力模拟即可

按照题目所说的意思即可。

cpp 复制代码
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 1e5 + 10;
#define de(x) cout << x << " ";
#define sf(x) scanf("%d", &x);
#define Pu puts("");
#define ll long long
int n, m, ans;
int a, b, c;  // 空的小栏,空的大栏,半空的大栏
int main() {
    cin >> n >> a >> b;
    c = 0;
    ans = 0;
    int x;
    while (n--) {
        cin >> x;
        // 按照题意进行简单模拟
        if (x == 1) {
            if (a > 0) {
                a--;
            } else if (b > 0) {
                b--;
                c++;
            } else if (c > 0) {
                c--;
            } else {
                ans++;
            }
        } else {
            if (b > 0) {
                b--;
            } else {
                ans += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

AcWing 5284. 构造矩阵

题解参考思路

上面的题解讲的很好

AC代码如下:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 1e5 + 9, mod = 1e9 + 7;
ll n, m, ans;  // 注意n和m数据范围是long long
int k;
ll qmi(ll x, ll y) {  // 快速幂
    ll res = 1;
    while (y) {
        if (y & 1)
            res = (ll)(res * x) % mod;
        x = (ll)(x * x) % mod;
        y >>= 1;
    }
    return res;
}
int main() {
    cin >> n >> m >> k;
    if ((n + m & 1) && k == -1)
        cout << 0 << endl;
    else
        cout << qmi(qmi(2, n - 1), m - 1) << endl;
    return 0;
}
相关推荐
多恩Stone1 天前
【3D-AICG 系列-1】Trellis v1 和 Trellis v2 的区别和改进
人工智能·pytorch·python·算法·3d·aigc
mit6.8241 天前
模运算|z函数 字符串匹配
算法
阿豪只会阿巴1 天前
【吃饭香系列】二周目|代码随想录算法训练营第七天|454.四数相加II |383. 赎金信 |15. 三数之和 |18. 四数之和
算法
小O的算法实验室1 天前
2025年COR SCI2区,考虑风场影响的无人机搜救覆盖路径规划精确界算法,深度解析+性能实测
算法·无人机·论文复现·智能算法·智能算法改进
xqqxqxxq1 天前
洛谷算法1-3 暴力枚举(NOIP经典真题解析)java(持续更新)
java·开发语言·算法
_OP_CHEN1 天前
【算法基础篇】(五十五)卡特兰数封神之路:从括号匹配到二叉树构造,组合数学的万能钥匙!
算法·蓝桥杯·c/c++·组合数学·卡特兰数·算法竞赛·acm/icpc
郝学胜-神的一滴1 天前
Python美学的三重奏:深入浅出列表、字典与生成器推导式
开发语言·网络·数据结构·windows·python·程序人生·算法
2501_901147831 天前
学习笔记:基于摩尔投票法的高性能实现与工程实践
笔记·学习·算法·性能优化
春日见1 天前
window wsl环境: autoware有日志,没有rviz界面/ autoware起不来
linux·人工智能·算法·机器学习·自动驾驶
rainbow68891 天前
PCL点云处理算法全解析
算法