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

AcWing 5283. 牛棚入住

题目数据范围不大,直接暴力模拟即可
按照题目所说的意思即可。

#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代码如下:

#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;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值