Codeforces 825 C Multi-judge Solving

本文解析了一道CodeForces C级别的编程题,通过将题目中的数组排序并从后向前遍历的方式,解决了如何确定解题顺序的问题。该算法确保每次都能选择当前条件下最优的解题策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目地址:http://codeforces.com/contest/825/problem/C
题意:告诉你一个初始值k,一定要满足k>=ai才能写第i题,然后k=max(k,a[i]);判断法官要借几道题才能把他的全部题目解决。
思路:把数组a排序,从后面开始遍历,如果遇见了a[i]/2 > k,就借一道题,把k的值翻倍(PS:这题是严格要是2倍,所以要用a[i] > k * 2,我就在这里wa了两次)

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long 
#define N 1010
#define M 50010
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
LL num[N];
bool cmp(LL a, LL b) {
    return a < b;
}
int main() {
    cin.sync_with_stdio(false);
    LL n, m;
    LL ans;
    while (cin >> n >> m) {
        for (int i = 0; i < n; i++) {
            cin >> num[i];
        }
        ans = 0;
        sort(num, num + n, cmp);
        for (int i = 0; i < n; i++) {
            while (num[i] > m * 2) {
                ans++;
                m *= 2;
            }
            m = max(num[i], m);
        }
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值