当前位置:网站首页>[牛客] [NOIP2015]跳石头
[牛客] [NOIP2015]跳石头
2022-07-06 17:14:00 【*DDL_GzmBlog】
前言
t a g : tag : tag:二分
二分答案
题意 :
思路 :
因为题目所求的是 最短的最大 ,很标准的一个二分询问方法
因此我们可以考虑二分最短距离,那么我们怎么check呢
很简单,显然对于现在的需要判断的 x,如果两个石头的差小于x的时候 , 我们肯定是要将其移走的
所以我们只需要判断移走的数量和m的关系即可
当然移走的状态我们可以通过last进行转移
code :
int L,n,m;
int a[N];
int i,j;
int b[N];
bool check(int x){
int cnt = 0;
int last = 0 ;
Fup(i,1,n+1){
if(a[i] - last < x) cnt++;
else last = a[i];
if(cnt > m) return false;
}
return true;
}
void solve(){
// cin>>L>>N>>M;
cin>>L>>n>>m;
Fup(i,1,n) cin>>a[i];
a[n+1] = L;
int l = 0 , r = L;
//cout<<ans<<endl;
while(l<=r){
int mid = (l+r)>>1;
if(check(mid)){
l = mid+1;
}
else r = mid - 1;
}
cout<<((l+r)>>1)<<endl;
}
signed main(){
//int t;cin>>t;while(t--)
solve();
return 0 ;
}
边栏推荐
- Mujoco produces analog video
- 深度学习框架TF安装
- How to get started and improve test development?
- Attention SLAM:一种从人类注意中学习的视觉单目SLAM
- Link sharing of STM32 development materials
- [Niuke classic question 01] bit operation
- Js+svg love diffusion animation JS special effects
- Mujoco finite state machine and trajectory tracking
- Attention slam: a visual monocular slam that learns from human attention
- Part IV: STM32 interrupt control programming
猜你喜欢
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
JS+SVG爱心扩散动画js特效
Dell筆記本周期性閃屏故障
.class文件的字节码结构
Threejs image deformation enlarge full screen animation JS special effect
. Bytecode structure of class file
Idea automatically imports and deletes package settings
第七篇,STM32串口通信编程
Distributed cache
stm32F407-------DAC数模转换
随机推荐
Attention slam: a visual monocular slam that learns from human attention
Stm32f407 ------- SPI communication
Set (generic & list & Set & custom sort)
Notes of training courses selected by Massey school
城联优品入股浩柏国际进军国际资本市场,已完成第一步
Model-Free Control
用tkinter做一个简单图形界面
深度学习简史(一)
dynamic programming
Cross-entrpy Method
【JokerのZYNQ7020】AXI_ EMC。
ActiveReportsJS 3.1中文版|||ActiveReportsJS 3.1英文版
Configuring the stub area of OSPF for Huawei devices
再聊聊我常用的15个数据源网站
浅谈测试开发怎么入门,如何提升?
stm32F407-------SPI通信
深度学习简史(二)
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
[Batch dos - cmd Command - Summary and Summary] - String search, find, Filter Commands (FIND, findstr), differentiation and Analysis of Find and findstr