• Educational Codeforces Round 25 C. Multi-judge Solving


    题目链接:http://codeforces.com/contest/825/problem/C

    C. Multi-judge Solving

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).

    Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty (no matter on what online judge was it).

    Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.

    With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.

    For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.

    Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.

    Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

    Input

    The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).

    The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).

    Output

    Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

    Examples

    Input

    3 3
    2 1 9

    Output

    1

    Input

    4 20
    10 3 6 3

    Output

     0

    题目大意:

    有个人想在CF上做题,每个题目有一个难度系数,现在这个人打算在CF上做n道题,这个人目前做出来的最高系数难度的题目是k,并且我们知道,对于难度系数为ai的题目,如果他已经做出来一道题d,且有2*d>=ai,他就能做出来ai这道题,否则的话,他就需要去BOJ上找一道题来做,使得他能做ai这道题。请问他至少要到BOJ上做几道题,才能全部做完n道题。

    题解:

    先排序,之后扫一遍,一边判断能做否,一边更新k。遇到不能做时候就去BOJ做一题ans++,然后继续更新k,输出ans...

    代码:

    #include<cstring>
    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define maxn 1005
    int main()
    {
    	int n,k,a[maxn];
    	while(cin>>n>>k)
    	{
    		int ans=0;
    		for(int i=0;i<n;i++)  scanf("%d",&a[i]);
    		sort(a,a+n);
    		for(int i=0;i<n;i++)
    		{
    			if(a[i]<k*2)  k=max(a[i],k);
    			else
    			{
    				while(a[i]>k*2) 
    				{
    					k*=2; ans++;
    				}
    				k=max(a[i],k);
    			}
    		}
    		cout<<ans<<endl;
    	}
    }
    
  • 相关阅读:
    android driver开发常见的英文缩写
    简析quakeIII中利用链表实现的内存管理(1)
    链表的建立
    boson netsim5.31平台上组建交换式网络
    第六周周记
    价值观作业
    C语言的知识与能力的自评
    学习进度表
    Web表格部分内容
    线性表部分知识
  • 原文地址:https://www.cnblogs.com/weimeiyuer/p/7204306.html
Copyright © 2020-2023  润新知