cf Educational Codeforces Round 25 C. Multi-judge Solving

2024-03-24 08:08

本文主要是介绍cf Educational Codeforces Round 25 C. Multi-judge Solving,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原题:
C. Multi-judge Solving
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 d>=(ai/2)
(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 ≤ 10^3, 1 ≤ k ≤ 10^9).

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

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
Note
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.

In the second example he can solve every problem right from the start.

中文:
给你两个数,n和k。其中表示有n道题目,k表示当前已经获得的难度值。
接下来给你n个数,表示n个题目的难度。
用户想在codeforce里面完成这n个题,完成一道题,用户就可以获得对应题目的难度值。但是用户想要完成一道难度为ai的题目,那么他之前必须完成过一道难度大于等于2×k的题目。如果ai题目的难度超过当前的2×k值,用户可以去别的oj刷题,别的oj的题目难度有无数种类,攒够难度值以后可以回来继续做ai。
现在问你用户最少在别的oj做多少题?

#include<bits/stdc++.h>
using namespace std;
int n,k;int num[1001];int main()
{ios::sync_with_stdio(false);while(cin>>n>>k){for(int i=1;i<=n;i++){cin>>num[i];}sort(num+1,num+1+n);int ans=0;for(int i=1;i<=n;i++){if(num[i]<=k*2)k=max(k,num[i]);else{int m=1;int j;for(j=k*2;j*2<num[i];j=j*2)m++;ans+=m;//    cout<<j<<endl;k=max(num[i],j);}//cout<<k<<endl;}cout<<ans<<endl;}return 0;
}

思路:

题目不太好理解。
首先从小到大排序,用初始化给定用户的难度值k去做题,每做一道题就看看能不能更新k值,如果做到第i个题,发现难度值不够。那么就去别的oj做自己当前难度最高可以承受的题目刷难度值,刷够了回来继续即可。

这篇关于cf Educational Codeforces Round 25 C. Multi-judge Solving的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/840966

相关文章

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

cf 164 C 费用流

给你n个任务,k个机器,n个任务的起始时间,持续时间,完成任务的获利 每个机器可以完成任何一项任务,但是同一时刻只能完成一项任务,一旦某台机器在完成某项任务时,直到任务结束,这台机器都不能去做其他任务 最后问你当获利最大时,应该安排那些机器工作,即输出方案 具体建图方法: 新建源汇S T‘ 对任务按照起始时间s按升序排序 拆点: u 向 u'连一条边 容量为 1 费用为 -c,

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

2014 Multi-University Training Contest 8小记

1002 计算几何 最大的速度才可能拥有无限的面积。 最大的速度的点 求凸包, 凸包上的点( 注意不是端点 ) 才拥有无限的面积 注意 :  凸包上如果有重点则不满足。 另外最大的速度为0也不行的。 int cmp(double x){if(fabs(x) < 1e-8) return 0 ;if(x > 0) return 1 ;return -1 ;}struct poin

2014 Multi-University Training Contest 7小记

1003   数学 , 先暴力再解方程。 在b进制下是个2 , 3 位数的 大概是10000进制以上 。这部分解方程 2-10000 直接暴力 typedef long long LL ;LL n ;int ok(int b){LL m = n ;int c ;while(m){c = m % b ;if(c == 3 || c == 4 || c == 5 ||

2014 Multi-University Training Contest 6小记

1003  贪心 对于111...10....000 这样的序列,  a 为1的个数,b为0的个数,易得当 x= a / (a + b) 时 f最小。 讲串分成若干段  1..10..0   ,  1..10..0 ,  要满足x非递减 。  对于 xi > xi+1  这样的合并 即可。 const int maxn = 100008 ;struct Node{int

CF 508C

点击打开链接 import java.util.Arrays;import java.util.Scanner;public class Main {public static void main(String [] args){new Solve().run() ;} }class Solve{int bit[] = new int[608] ;int l

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja