当前位置: 首页 > article >正文

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


http://www.kler.cn/news/108585.html

相关文章:

  • SAP从入门到放弃系列之QM动态修改(Dynamic Modification)
  • 挖掘业务场景的存储更优解
  • Android开发知识学习——登录和第三方授权
  • 前端和后端 优化
  • javaEE -8(9000字详解网络编程)
  • 【面试经典150 | 栈】简化路径
  • 数字孪生与智慧城市:开启未来智慧生活
  • Spring Cloud之Docker的学习【详细】
  • 【每日一题】补档 CF487B. Strip | 数据结构杂烩 -> 单调队列 | 困难
  • 【python】pip的使用
  • C++之C++11引入enum class与传统enum关键字总结(二百五十一)
  • 如何通过adb控制安卓手机wifi
  • 手机apn介绍
  • 66 内网安全-域横向批量atschtasksimpacket
  • PostgreSQL InvalidMessage Cache 同步机制
  • 如何确保PCIe Gen3通道的信号质量
  • SpringBoot2.7.14整合redis7
  • 【Java】HashMap集合
  • CommunityToolkit.Mvvm 加速 MVVM 开发
  • 环形链表-力扣
  • 【影刀演示_发送邮件的格式化HTML留存】
  • 【MATLAB源码-第61期】基于蜣螂优化算法(DBO)的无人机栅格地图路径规划,输出最短路径和适应度曲线。
  • 玩转视图变量,轻松实现动态可视化数据分析
  • 深度神经网络的数学原理:基于超平面、半空间与线性区域的表示
  • stm32通过AT指令与esp8622通信
  • JVM——GC垃圾回收器
  • 06 MIT线性代数-线性无关,基和维数Independence, basis, and dimension
  • SpreadJS 16.2.2 + GcExcel 6.2.3 相结合,还有更强的吗
  • Android WMS——WM窗口管理(八)
  • 小程序request请求封装