Educational Codeforces Round 25 C. Multi-judge Solving

来源:互联网 发布:局域网打印机端口 编辑:程序博客网 时间:2024/04/30 11:45

题目网址: Educational Codeforces Round 25 C. Multi-judge Solving

题意分析:

题意是, 一个要做某oj上n道题,且给出每题的难度a1, a2, …, an. 要做出某题—难度ai, 必须满足做过的最难的题的难度k, k>=ai/2. 题目给出当前他做过最难的题难度为k. 如果他现在无法做出这个oj上的n道题, 就需要去另外的oj刷题来提高他做过的最高难度, 求他至少需要去别的oj做多少题才能做完这个oj上n道题.

根据题意, 可知

  • 先对n道题难度排序
  • 然后遍历n道题的难度, 若当前难度可以做出来,即满足k>=ai/2, 且当前难度比k大, 则更新k的值, 即 k = ai
  • 若当前难度做不出来, 则让k扩大两倍并计数cnt,直到满足k>=ai/2, 并判断当前难度是否大于k,是则更新k的值
  • 最终计数 cnt 为所求

代码:

#include <iostream>#include <algorithm>using namespace std;const int SIZE = 1e3+5;long long score[SIZE];int main(int argc, char const *argv[]){    long long n, k;    while (~scanf("%I64d %I64d", &n, &k))    {        int cnt = 0;        for (int i = 0; i < n; ++i)        {            scanf("%I64d", &score[i]);        }        sort(score, score+n);        for (int i = 0; i < n; ++i)        {            if(score[i] <= 2*k)            {                k = max(score[i], k);            }            else            {                while (score[i] > 2*k)                {                    k <<= 1;                    ++cnt;                }                k = max(score[i], k);            }        }        printf("%d\n", cnt);    }    return 0;}
原创粉丝点击