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;
}
相关推荐
SandySY25 分钟前
品三国谈人性
算法·架构
敢敢J的憨憨L31 分钟前
GPTL(General Purpose Timing Library)使用教程
java·服务器·前端·c++·轻量级计时工具库
小欣加油33 分钟前
leetcode 62 不同路径
c++·算法·leetcode·职场和发展
夏鹏今天学习了吗34 分钟前
【LeetCode热题100(38/100)】翻转二叉树
算法·leetcode·职场和发展
夏鹏今天学习了吗34 分钟前
【LeetCode热题100(36/100)】二叉树的中序遍历
算法·leetcode·职场和发展
DTS小夏38 分钟前
算法社Python基础入门面试题库(新手版·含答案)
python·算法·面试
让我们一起加油好吗1 小时前
【C++】封装红黑树模拟实现 set 和 map
linux·c++·set·map·红黑树
Mr.Ja1 小时前
【LeetCode热题100】No.11——盛最多水的容器
算法·leetcode·贪心算法·盛水最多的容器
hsjkdhs1 小时前
C++之类的继承与派生
开发语言·c++
冷徹 .1 小时前
2024ICPC区域赛香港站
数据结构·c++·算法