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;
}
相关推荐
野犬寒鸦7 分钟前
面试常问:HTTP 1.0 VS HTTP 2.0 VS HTTP 3.0 的核心区别及底层实现逻辑
服务器·开发语言·网络·后端·面试
geovindu11 分钟前
python: Null Object Pattern
开发语言·python·设计模式
lisus200718 分钟前
GO并发统计文件大小
开发语言·后端·golang
梦游钓鱼26 分钟前
Logger.h和Logger.cc文件分析
开发语言·c++
CRMEB系统商城32 分钟前
CRMEB标准版系统(PHP)v6.0公测版发布,商城主题市场上线~
java·开发语言·小程序·php
mit6.82434 分钟前
Agent memory发展路线
算法
青桔柠薯片38 分钟前
Linux I/O多路复用:深入浅出poll与epoll
linux·运维·服务器·算法
yangminlei42 分钟前
openclaw对接飞书
开发语言·python·飞书
REDcker1 小时前
Linux C++ 内存泄漏排查分析手册
java·linux·c++
临溟夜空的繁星1 小时前
C++ STL-- vector
开发语言·c++