Codeforces 825 C Multi-judge Solving

来源:互联网 发布:笔记本温度监控软件 编辑:程序博客网 时间:2024/05/16 10:05

题目地址: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 0x3f3f3f3f3f3f3f3fusing 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;}