Educational Codeforces Round 44#985DSand Fortress+二分
传送门:送你去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+二分的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 ’A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
- Educational Codeforces Round 60 C 思维 + 二分
https://codeforces.com/contest/1117/problem/C 题意 在一个二维坐标轴上给你一个起点一个终点(x,y<=1e9),然后给你一串字符串代表每一秒的风向, ...
- Educational Codeforces Round 64 -C(二分)
题目链接:https://codeforces.com/contest/1156/problem/C 题意:给出n个数和整形数z,定义一对数为差>=z的数,且每个数最多和一个数组成对,求最多有多 ...
- Educational Codeforces Round 44 (Rated for Div. 2) F - Isomorphic Strings
F - Isomorphic Strings 题目大意:给你一个长度为n 由小写字母组成的字符串,有m个询问, 每个询问给你两个区间, 问你xi,yi能不能形成映射关系. 思路:这个题意好难懂啊... ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- 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 ...
随机推荐
- Promise异步编程解决方案
Promise是ES6中新增的异步编程解决方案,体现在代码中它是一个对象,可以通过 Promise 构造函数来实例化. 其最基本的使用 new Promise(function(resolve,rej ...
- 【Android】java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has android.permission.READ_PHONE_STATE
RT, 异常信息如下: java.lang.SecurityException: getDeviceId: Neither user 10065 nor current process has and ...
- 关于HostnameVerifier接口的解读
在项目中我们需要调用https接口请求.我们使用httpClient,构建HttpClient对象时涉及到使用HostnameVerifier接口实例. HostnameVerifier接口定义如下: ...
- nginx基本运维及常用配置
nginx基本运维及常用配置 ========================================================== 基本运维 nginx 的启动 nginx -c /p ...
- 【Java例题】3.5 级数之和
5. 计算级数之和: y=3*1!/1-3^2*2!/2^2+3^3*3!/3^3-...+ (-1)^(n-1)*3^n*n!/n^n. 这里的"^"表示乘方,"!&q ...
- iView 实现可编辑表格
create at: 2019-02-20 组件 <i-table highlight-row ref="currentRowTable" :columns="co ...
- [转载]使用Java操作Mongodb
HelloWorld程序 学习任何程序的第一步,都是编写HelloWorld程序,我们也不例外,看下如何通过Java编写一个HelloWorld的程序. 首先,要通过Java操作Mongodb,必须先 ...
- C语言编程入门之--第五章C语言基本运算和表达式-part2
5.1.4 再来一个C库函数getchar吸收回车键 回车键也是一个字符,在使用scanf的时候,输入完毕要按下回车键,这时候回车键也会被输入到stdin流中,会搞乱我们的程序. 注意:stdin是输 ...
- 趣味CSS3效果挑战小汇总
众所周知,在CSS3中产生了诸多优秀的特性,现在就来分享一下我这段时间对于这些特性的效果实践,希望对大家有所启发. 挑战1: 画一个对话框 要画一个对话框,首先来学习做一个三角形.其实非常的简单. & ...
- 关于JSP页面的静态包含和动态包含
JSP中有两种包含:静态包含:<%@include file="被包含页面"%> 和 动态包含:<jsp:include page="被包含页面&quo ...