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;
}
相关推荐
Felven19 分钟前
B. Deja Vu
数据结构·算法
小玮看世界29 分钟前
[Python]螺旋遍历 vs 最短路径:方向控制类算法的“同源异流”
开发语言·python·算法
月华路34 分钟前
《模型不玄学》第14章 标签、损失与样本权重
人工智能·算法·机器学习
黄金龙PLUS36 分钟前
SPARKLE置换算法的优缺点
算法·网络安全·密码学·哈希算法·同态加密
不会就选b37 分钟前
算法日常・每日刷题--<贪心>3
数据结构·算法·leetcode
行者全栈架构师1 小时前
WorkBuddy 实战:把一份 200 页年报变成可上台的投资分析 PPT
人工智能·算法·全栈
微三云生态系统架构师-彭丹1 小时前
矩阵拼团系统设计:先付款先排队的订单排序与自动返本算法
线性代数·算法·矩阵
@MMiL1 小时前
基于Keil 的实时参数标定和值观测
算法
无限码力2 小时前
华为非AI方向笔试真题【工厂落点最小加权路程】
算法·华为·华为非ai方向笔试真题·华为笔试真题·华为最新笔试真题·华为笔试题库
residual_fan2 小时前
数据缺失填补算法之CUR-Estimator
算法·数据挖掘·数据分析