当前位置:网站首页>1433: [example 1] angry cattle
1433: [example 1] angry cattle
2022-06-09 05:52:00 【c_ yy_】
- One pass portal
- Typical examples of dichotomy , Find the minimum and the maximum , Just use two points
- Two points + The judgment is feasible
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+3;
int n,m,x[N];
bool check(int d){
// To see if it works
int cow=1,rgt=x[1]+d;
for(int i=2;i<=n;i++){
if(x[i]<rgt) continue;// The distance is small , next
++cow;// feasible , Number of cattle plus one
rgt=x[i]+d;// Next position
}
return cow>=m;// Return value
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>x[i];
sort(x+1,x+n+1);// The cowshed position input is out of order , Need to sort
int l=0,r=x[n]-x[1];
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) l=mid+1;// Two points to the right
else r=mid-1;// Two points to the left
}
cout<<r<<endl;
return 0;
}
边栏推荐
- MySql中事务详细理解学习(事务管理、事务隔离级别、事务传播机制)
- 【论文】CBAM: Convolutional Block Attention Module
- Several implementation methods of redis distributed lock
- threadlocal 解析
- Alibaba cloud AI training camp - SQL basics 3: complex query methods - views, subqueries, functions, etc
- Some concepts in network planning
- Yolov5-6.0系列 | yolov5的模型网络构建
- Morsel-Driven Parallelism: 一种NUMA感知的并行Query Execution框架
- Notes on index building and search execution in Lucene
- 图像处理-特征融合相关延伸
猜你喜欢

MySql中事务详细理解学习(事务管理、事务隔离级别、事务传播机制)

Data inconsistency between the reids cache and the database, cache expiration and deletion

Two methods of unbutu installing ffmpeg

和琪宝的重庆之旅~

Practical guide to GStreamer application development (II)

Alibaba cloud AI training camp - SQL basics 3: complex query methods - views, subqueries, functions, etc

If you become a qualified technical manager

SET DECIMAL_V2=FALSE及UDF ERROR: Cannot divide decimal by zero及Incompatible return types DECIMAL问题排查

数据治理:如何提高企业数据质量?
groupby函数详解
随机推荐
数据治理:如何提高企业数据质量?
Topic25——4. 寻找两个正序数组的中位数
matlab----多项式、函数
SET DECIMAL_ V2=false and UDF error: cannot divide decimal by zero and incompatible return types decimal
Quelles sont les informations contenues dans le certificat SSL?
JVM basic theory.
Several implementation methods of redis distributed lock
ThreadLocal parsing
Google Colab 使用小贴士
Heqibao's trip to Chongqing ~
计网中的一些概念
In latex, \cdots is followed by a sentence. What's wrong with the format of the following sentence.
@Differences between jsonformat and @datetimeformat
Gstreamer应用开发实战指南(二)
C语言编写计算文件CRC的小程序
Leetcode 1037. Effective boomerang
三大队列cxq,entrylist,waitset 个人理解分析
Redis cache avalanche, penetration and breakdown
MySql使用模糊查询中文时查询语句出现乱码的解决
Time stamp verification code signing method for code signing certificate