传送门:送你去985D;

题意:

你有n袋沙包,在第一个沙包高度不超过H的条件下,满足相邻两个沙包高度差小于等于1的条件下(注意最小一定可以为0),求最少的沙包堆数;

思路:

画成图来说,有两种可能,一种是y=h-x一次函数和常函数y=x组合,还有一种是先上升后下降的函数,注意斜率绝对值都是1;

二分答案,具体来说,我是二分了最大高度,主要是check()比较要思考,(昨天晚上没有细心写check,错过了很多AC:);

这个check中;如果最大高度 mid 比m小,说明不会有折线,直接考虑三角形加矩形的情况。

       如果最大高度mid 比m大,考虑三角形,和最大高度左边的情况,利用贪心,左边区域的最低一定是m。

      上面的情况中,如果区域的容量比较宽裕(比n大)就放大答案,否则缩小;

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator> using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull; /*-----------------show time----------------*/
ll n,m,ans = 2e18+;
ll cal(ll x)
{
return 1ll*x*(x+)/;
}
bool check(ll x)
{
ll st = cal(x);
ll tmp = x; //计算完整三角形区域;
if(x<=m) {
if(st<=n)
{
tmp = tmp+ 1ll*((n-st)/x);
if((n-st)%x)tmp++;
ans = min(tmp,ans);
return true;
}
else
{
return false;
}
}
else {
if(st<=n)
{
ll y = n - st; //n中剩下的
ll q = x - m -; //区域左边 ll c = cal(q) + 1ll* m *(x-m);//
if(c > y)return false;
tmp += x-m; //因为第一个也算,所以不减1;
y -= c;
tmp = tmp + y/x;
if(y%x!=)tmp++; //显然,如果还有多余,一定比x(最大值)小,找个适当位子插入就ok
ans = min(ans,tmp);
return true;
}
else
return false;
}
}
int main(){
OKC;
cin>>n>>m;
ll le = , ri = 1ll*2e10;
//我是二分整个区域的最大值。
while(le <= ri)
{ ll mid = (le + ri)>>;
// cout<<mid<<endl;
if(check(mid))
{
le = mid + ;
}
else ri = mid - ;
}
cout<<ans<<endl;
return ;
}

CF985D

Educational Codeforces Round 44#985DSand Fortress+二分的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Educational Codeforces Round 44 (Rated for Div. 2)

    题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...

  4. Educational Codeforces Round 60 C 思维 + 二分

    https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...

  5. Educational Codeforces Round 64 -C(二分)

    题目链接:https://codeforces.com/contest/1156/problem/C 题意:给出n个数和整形数z,定义一对数为差>=z的数,且每个数最多和一个数组成对,求最多有多 ...

  6. Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings

    F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...

  7. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

随机推荐

  1. hdoj 4706 Children's Day

    题目意思就是用a-z组成一个N,然后到z后又跳回a,输出宽从3到10的N. #include <stdio.h> #include <string.h> char s[14][ ...

  2. HttpsUtils

    package io.renren.modules.jqr.util; import java.io.BufferedReader; import java.io.InputStream; impor ...

  3. hdu 6397 Character Encoding (生成函数)

    Problem Description In computer science, a character is a letter, a digit, a punctuation mark or som ...

  4. 【算法】【排序】【插入类】希尔排序 ShellSort

    #include<stdio.h> #include <time.h> #include<stdlib.h> int main(){ ]; //设立随机数 sran ...

  5. Linux下安装jupyter

    又是美好的一天     开开心心写代码 1. 安装ipython, jupyter pip install ipython pip install jupyter 2. 生成配置文件[root@50e ...

  6. 世界十大OTA公司盘点

    世界十大OTA公司盘点 文/刘照慧(执惠旅游联合创始人,首发百度百家) 全球在线旅游公司(OTA)经过多年发展,已经形成较为成熟的商业模式,各大巨头跑马圈地,格局初现, 这两篇文章就梳理出全球按市值( ...

  7. 使用IDEA打包scala程序并在spark中运行

    一.首先配置ssh无秘钥登陆, 先使用这条命令:ssh-keygen,然后敲三下回车: 然后使用cd .ssh进入 .ssh这个隐藏文件夹: 再创建一个文件夹authorized_keys,使用命令t ...

  8. Liunx查看后1000行的命令以及查看中间部分

    linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...

  9. C#.Net实现AutoCAD块属性提取

    https://blog.csdn.net/dengyiyu/article/details/2201175 本文主要给大家介绍一下SmartSoft中用C#.Net实现AutoCAD块属性提取的方法 ...

  10. 理解-NumPy

    # 理解 NumPy 在这篇文章中,我们将介绍使用NumPy的基础知识,NumPy是一个功能强大的Python库,允许更高级的数据操作和数学计算. # 什么是 NumPy? NumPy是一个功能强大的 ...