Codeforces Round 926 (Div. 2)

A. Sasha and the Beautiful Array(模拟)

思路

最大值减去最小值

cpp 复制代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 110;
int a[N];
 
int main(){
    int t, n;
    cin>>t;
    while(t--){
        cin>>n;
        for(int i = 0; i < n; i++) cin>>a[i];
        int res = *max_element(a, a + n) - *min_element(a, a + n);
        cout<<res<<endl;
    }
}

B. Sasha and the Drawing(思维)

思维

前 2n - 2 个格子每个贡献两条对角线,剩下 2 个每个贡献一条对角线

cpp 复制代码
#include<iostream>
using namespace std;

int main(){
    int t, n, k;
    cin>>t;
    while(t--){
        cin>>n>>k;
        //如果是前 2n - 2 个格子,那就除 2 向上取整
        if(k <= 4 * n - 4) cout<<(k - 1) / 2 + 1<<endl;
        else cout<<2 * n - 2 + k - (4 * n - 4)<<endl;
    }
    return 0;
}

C. Sasha and the Casino(倍投法)

思路

赢的时候可以赢 y * (k - 1), 那么如果输的时候余额必须大于 y * (k - 1),k 为 2 就是倍投法

cpp 复制代码
#include<iostream>
using namespace std;

int main(){
    int t, k, x, a;
    cin>>t;
    while(t--){
        cin>>k>>x>>a;
        //y 存储每次需要的本金,sum 存储总共需要的本金
        long long sum = 0, f = 1;
        for(int i = 0; i <= x; i++){
            y = sum / (k - 1) + 1;
            sum += y;
            if(sum > a){
                f = 0;
                break;
            }
        }
        if(f) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}
相关推荐
星释21 分钟前
Rust 练习册 :深入探索XOR加密与流密码
开发语言·网络·rust
郝学胜-神的一滴26 分钟前
Effective STL 第9条:C++容器元素删除技巧详解
开发语言·c++·程序人生·stl
提娜米苏27 分钟前
Bash Shell脚本学习——唇读数据集格式修复脚本
开发语言·学习·bash
larance30 分钟前
python中的鸭子类型
开发语言·python
树在风中摇曳34 分钟前
LeetCode 1658 | 将 x 减到 0 的最小操作数(C语言滑动窗口解法)
c语言·算法·leetcode
Ma_Hong_Kai35 分钟前
带复选框的combox
c++·mfc
不夜牛仔1 小时前
算法笔记17 - 贪心算法介绍与思路 | 路灯摆放问题 | 活动安排问题 | 最低字典序拼接 | 金条分割问题 | 项目投资问题
笔记·算法·贪心算法
丙寅1 小时前
微信小程序反编译遇到 TypeError: _typeof3 is not a function
开发语言·javascript·ecmascript
醇氧1 小时前
MAC 安装openJDK8
java·开发语言
海阔天空在前走1 小时前
JAVA中六种策略模式的实现
java·开发语言·策略模式