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 ...
随机推荐
- 【Java】判断字符串是否含字母
用正则表达式,示例代码如下: String str = "123abc"; Pattern.compile("(?i)[a-z]]").matcher(str) ...
- 【iOS】file not found: .../Build/Products/Debug-iphonesimulator file not found
今天又遇到了这个问题: ld: file not found: /Users/***/Library/Developer/Xcode/DerivedData/***-dfscappaygvbougtb ...
- HTML 第4章初始CSS3
什么是CSS? CSS全称为层叠样式表,通常又称为风格样式表. 引用CSS样式: 语法: <h1 styske="color:red;">style属性的应用</ ...
- WPF中如何禁用空格键(或其他键)
在选择的控件中添加KeyDown event method private void OnKeyDown(object sender, KeyEventArgs e){ if (e.Key == Ke ...
- Linux基础进程管理
一.进程 了解如进程的: • PID,PPID • 当前的进程状态 • 内存的分配情况 • CPU和已花费的实际时间 • 用户UID,他决定进程的特权 (一).静态查看进程 # ps axu | le ...
- 控制台出现_ob_:Obsever
我遇到一个问题:我的代码想让他点击之后得到经纬度坐标数组,然后我就这样写了 然而控制台却读取出了
- Quartz CronTrigger定时器表达式大全
CronTrigger是基于Calendar-like调度的.当你需要在除星期六和星期天外的每天上午10点半执行作业时,那么应该使用CronTrigger.正如它的名字所暗示的那样,CronTrigg ...
- [转载]关于ActiveMQ集群
转载于 http://blog.csdn.net/nimmy/article/details/6247289 近日因工作关系,在研究JMS,使用ActiveMQ作为提供者,考虑到消息的重要,拟采用Ac ...
- 分布式存储——ceph 的 python 基础接口
python 使用 boto 库完成分布式存储读.写.判断接口 import boto import boto.s3.connection from boto.s3.key import Key im ...
- 微信小程序项目总结-记账小程序(包括后端)
一.小程序部分 这是理财系统的前端,江苏海洋大学微信小程序比赛,最后获得了一等奖 GitHub:https://github.com/GeorgeLeoo/finance 1. 项目描述 (1). 此 ...