当前位置:网站首页>Luogu p1873 [coci 2011/2012 5] Eko / tree cutting dichotomy
Luogu p1873 [coci 2011/2012 5] Eko / tree cutting dichotomy
2022-07-21 01:25:00 【Prudento】
# [COCI 2011/2012 #5] EKO / Cut down trees
## Title Description
Lumberjack Mirko Need to cut $M$ Meters of wood . Yes Mirko It's a simple job for me , Because he has a beautiful new logging machine , You can cut down forests like wildfire . however ,Mirko Only one row of trees is allowed to be cut down .
Mirko The work flow of the logging machine is as follows :Mirko Set a height parameter $H$( rice ), The logging machine raises a huge saw blade to a height $H$, And saw off all the trees $H$ High part ( Of course , Trees are no higher than $H$ The part of the meter remains the same ).Mirko You get the sawn part of the tree . for example , If the height of a row of trees is $20,15,10$ and $17$,Mirko Raise the saw blade to $15$ Height of meters , After cutting, the remaining height of the tree will be $15,15,10$ and $15$, and Mirko From the $1$ The tree gets $5$ rice , From $4$ The tree gets $2$ rice , Get... Together $7$ Rice wood .
Mirko Pay great attention to ecological protection , So he won't cut too much wood . That's why he set the saw blade of the logging machine as high as possible . Please help Mirko Find the maximum integer height of the logging machine saw blade $H$, So that he can get at least $M$ rice . let me put it another way , If it rises again $1$ rice , He will not get $M$ Rice wood .
## Input format
The first $1$ That's ok $2$ It's an integer $N$ and $M$,$N$ Indicates the number of trees ,$M$ The total required length of wood .
The first $2$ That's ok $N$ An integer representing the height of each tree .
## Output format
$1$ It's an integer , Indicates the highest height of the saw blade .
## Examples #1
### The sample input #1
```
4 7
20 15 10 17
```
### Sample output #1
```
15
```
## Examples #2
### The sample input #2
```
5 20
4 42 40 26 46
```
### Sample output #2
```
36
```
## Tips
about 100\%100% Test data for ,1≤N≤10^6,1≤M≤2×10^9, The height of the tree <10^9, The sum of the height of all trees >M.
.
Ideas :
Simple dichotomy , This question is obviously a binary search for the right H, Then determine the boundary and check Function . The boundary is the height range of the tree ,check Function is to judge whether we can get M Above the height .
AC Code :
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m,a[N],minh=2e9,maxh;
long long h;
bool check(int mid) {
long long cnt=0;
for(int i=0;i<n;i++){
if (a[i] >= mid)cnt += a[i] - mid;
}
if (cnt >= m)return true;
else return false;
}
void bs(int l, int r) {
// Two points to determine the highest suitable height , Search from the height range of the tree
while (l < r) {
int mid = l + r + 1 >> 1;
if (check(mid))l = mid;
else r = mid - 1;
}
h = l;
}
int main(){
cin >> n >> m;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (minh > a[i])minh = a[i];
if (maxh < a[i])maxh = a[i];
}
sort(a, a + n);
bs(minh, maxh);
cout << h;
return 0;
}
边栏推荐
- 数据库系统原理与应用教程(028)—— MySQL 的数据完整性(一):数据完整性概述
- VMware startup error: exception 0xc00000005 and windwos11 have no Hyper-V solution
- Unity: PC development, click the object with the mouse to trigger the object to change the material
- 丢失了数据库密码,如何恢复?
- vivo官网APP全机型UI适配方案
- WebRTC系列-SDP之类关系梳理
- The way of practicing and fighting weird: the difference between NPM and yarn
- 【03】通过你的CPU主频,我们来谈谈“性能”究竟是什么?
- Question 128 of Li Kou: longest continuous sequence
- iptables防止nmap端口扫描
猜你喜欢
十分鐘生成影視級室內設計效果,紅星美凱龍設計雲如何昇級傳統家居行業
IDEA:Lambda expression are not supported at language level ‘5‘
Detailed explanation of TestNG automated testing framework
【LeetCode】12. Balanced binary tree
Encapsulation, inheritance, polymorphism
[731. My schedule II]
WebRTC系列-SDP之类关系梳理
Detailed explanation of program environment and pretreatment
acwing 867. 分解质因数
[leetcode] 12. Arbre binaire équilibré · Arbre binaire équilibré
随机推荐
3 种缓存更新策略是怎样的?
数据库系统原理与应用教程(027)—— MySQL 修改表中数据(三):改(update)
Classes and objects (top)
類和對象(上)
Baidu PaddlePaddle easydl helps manufacturing enterprises with intelligent transformation
[model evaluation]
洛谷 P1873 [COCI 2011/2012 #5] EKO / 砍树 二分
Day106.尚医通:数据字典列表、EasyExcel、数据字典导入导出、集成Redis缓存
I want to display the number of records in the SQL database table on the label label
Warning FailedScheduling 8s default-scheduler 0/3 nodes are available: 1 Insufficient memory
New features of globalization under the background of accelerated development of informatization
暑假安全第二次作业
EASYCODE plug-in use
类和对象(上)
Discussion on the new trend of network security technology
Unity:测试旋转 函数
Xing No
Baidu PaddlePaddle easydl helps manufacturing enterprises with intelligent transformation
Learn about spark project on nebulagraph
数据库系统原理与应用教程(022)—— MySQL 支持的数据类型总结