C. Multi-judge Solving 贪心+模拟
来源:互联网 发布:盛世传奇翅膀进阶数据 编辑:程序博客网 时间:2024/04/30 22:43
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 difficultyd on Decoforces is as hard as the problem with difficultyd on any other judge).
Makes has chosen n problems to solve on Decoforces with difficultiesa1, 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 difficultyk.
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.
The first line contains two integer numbers n,k (1 ≤ n ≤ 103,1 ≤ k ≤ 109).
The second line contains n space-separated integer numbersa1, a2, ..., an (1 ≤ ai ≤ 109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
3 32 1 9
1
4 2010 3 6 3
0
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty9, he should solve problem with difficulty no less than5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem3.
In the second example he can solve every problem right from the start.
题意:要求做完给出的所有难度的题,当给出的题的难度大于K的2倍时,必须从其他OJ做题以此更新K值让2*k大于当前题目才能解题成功,问做完需要额外做几题。
思路:从小到大排序,一道道做,不能做就一直乘2;更新K,能做就比较K和a[i]的大小,更新k
#include <bits/stdc++.h>#define LL long longusing namespace std;const int AX = 1e3+666;LL a[AX];LL n ,k ;int main(){while( cin>>n>>k ){for( int i = 1 ; i <= n; i++ ){cin>>a[i];}sort( a + 1 , a + n + 1 );int ans = 0;for( int i = 1 ; i <= n; i++ ){if( a[i] > 2*k ){k *= 2 ;ans++;i--; //这里wa了,一定要多次判断,开始没太明白题意。。}else{k = max(a[i],k);}}cout<<ans<<endl;}return 0;}
- C. Multi-judge Solving 贪心+模拟
- Educational Codeforces Round 25 C Multi-judge Solving 贪心
- Codeforces 825 C Multi-judge Solving
- codeforces 825C (Multi-judge Solving)
- 【Codeforces 825 C. Multi-judge Solving】
- Codeforces 825C Multi-judge Solving【水题】
- codeforces825C-Multi-judge Solving
- Educational Codeforces Round 25 C. Multi-judge Solving
- Educational Codeforces Round 25 C. Multi-judge Solving
- cf Educational Codeforces Round 25 C. Multi-judge Solving
- CodeForces 825A Multi-judge Solving(阅读题)
- uva489 Hangman Judge (模拟)
- Gym - 101102C C. Bored Judge 线段树+贪心+反向推
- codeforces--C - Anya and Ghosts(贪心+模拟)
- Codeforces 733C (模拟,贪心)
- Codeforces 749C Voting 贪心+模拟
- Codeforces 797C Minimal String 贪心+模拟
- solving
- 存储过程的导入List<Object>集合
- ES6中集合的应用
- Python之访问dict
- 40个Java集合面试问题和答案
- 数据库的导入导出、以及更新服务器上的oracle数据库
- C. Multi-judge Solving 贪心+模拟
- shape. Shape Distance and Matching 形状距离与匹配
- 最近在开始捡起java,所以会定期更新写java 的一些组件,有兴趣的朋友可以看下
- 物理题。。。
- js 正则表达式
- 集合常用的简单的知识点
- Spring bean的自动装配
- 前端十个基础面试题及答案
- 二分查找(折半查找)的思路与实现 java实现