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;
}
相关推荐
List<String> error_P几秒前
经典回溯算法解析
python·算法
陆嵩几秒前
从一个小例子学习方程组求解超节点(supernodal)算法
学习·算法·amd·重排·超节点·supernadal·消去树
清水白石0084 分钟前
依赖注入的优雅:不用框架,在 Python 中实现轻量级依赖注入
开发语言·python
游乐码7 分钟前
c#里氏替换
开发语言·c#
未来之窗软件服务8 分钟前
AI人工智能(十二)C# 运行sensevoice onnx—东方仙盟练气期
开发语言·人工智能·c#·仙盟创梦ide·东方仙盟
weixin_4404016910 分钟前
Python数据分析-合并清洗与转换(concat+lambda函数+apply+删除drop/替换数据replace)
开发语言·python·数据分析
Fms_Sa11 分钟前
设计并实现日期类Date,它至少包含下列特性:
c++·算法
Dxy123931021612 分钟前
Python如果遇见乱码可以通过二进制判断是什么编码吗?
开发语言·python
TTBIGDATA18 分钟前
【Atlas】Atlas 搜索时报 `__AtlasUserProfile` 不存在导致事务回滚
开发语言·python·ambari·kerberos·ranger·atlas·bigtop
devmoon20 分钟前
区块链预言机(Oracle)解析:Polkadot、以太坊与 Solana 如何把现实世界带入链上?
开发语言·oracle·区块链·信息与通信·以太坊·polkadot·solana