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;
}
相关推荐
良木生香几秒前
【数据结构-初阶】二叉树(1)---树的相关概念
c语言·数据结构·算法·蓝桥杯
良木生香1 分钟前
【数据结构-初阶】二叉树(2)---堆
c语言·数据结构·算法·蓝桥杯
ppo_wu2 分钟前
介绍下CompletableFuture的用法
java·开发语言
吴佳浩 Alben3 分钟前
Python入门指南(七) - YOLO检测API进阶实战
开发语言·python·yolo
KingRumn6 小时前
Linux信号之标准信号与实时信号
linux·算法
沐知全栈开发8 小时前
HTML5 浏览器支持
开发语言
wasp5208 小时前
AgentScope Java 核心架构深度解析
java·开发语言·人工智能·架构·agentscope
WHOVENLY8 小时前
【javaScript】- 笔试题合集(长期更新,建议收藏,目前已更新至31题)
开发语言·前端·javascript
慌糖8 小时前
流-为序列化解释
开发语言
LXS_3579 小时前
Day 18 C++提高 之 STL常用容器(string、vector、deque)
开发语言·c++·笔记·学习方法·改行学it