思路:二分答案,时间复杂度O(nlgn).

若个数为x,那么算出这种情况下提供的水管的最大值和最小值与n比较即可,注意x个分离器需要减去x-1个水管。

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long int
using namespace std;
LL n, k;
LL calSum(LL ba, LL i){
return ((2*ba + i - 1) * i)/2;
}
LL bin_search(LL l, LL r){
LL ans = 0x7fffffff;
while(l <= r){
LL mid = (l + r) >> 1;
LL up = min(n + mid - 1, k);
LL tmp1 = calSum(2, mid), tmp2 = calSum(up - mid + 1, mid);
if(tmp1 <= n + mid - 1 && tmp2 >= n + mid -1){
ans = min(ans, mid);
r = mid - 1;
}
else if(tmp1 > n + mid - 1) r = mid - 1;
else if(tmp2 < n + mid - 1) l = mid + 1;
}
if(ans != 0x7fffffff) return ans;
else return -1;
}
int main(){
while(cin >> n >> k){
if(n == 1) printf("0\n");
else cout << bin_search(1, k-1) << endl;
}
return 0;
}

CodeForces 287B Pipeline的更多相关文章

  1. CodeForces 287B Pipeline (水题)

    B. Pipeline time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  2. [贪心,dp] Educational Codeforces Round 71 (Rated for Div. 2) C. Gas Pipeline (1207C)

    题目:http://codeforces.com/contest/1207/problem/C   C. Gas Pipeline time limit per test 2 seconds memo ...

  3. Codeforces 1207C Gas Pipeline (dp)

    题目链接:http://codeforces.com/problemset/problem/1207/C 题目大意是给一条道路修管道,相隔一个单位的管道有两个柱子支撑,管道柱子高度可以是1可以是2,道 ...

  4. redis大幅性能提升之使用管道(PipeLine)和批量(Batch)操作

    前段时间在做用户画像的时候,遇到了这样的一个问题,记录某一个商品的用户购买群,刚好这种需求就可以用到Redis中的Set,key作为productID,value 就是具体的customerid集合, ...

  5. Building the Testing Pipeline

    This essay is a part of my knowledge sharing session slides which are shared for development and qua ...

  6. Scrapy:为spider指定pipeline

    当一个Scrapy项目中有多个spider去爬取多个网站时,往往需要多个pipeline,这时就需要为每个spider指定其对应的pipeline. [通过程序来运行spider],可以通过修改配置s ...

  7. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  8. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  9. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

随机推荐

  1. C# Activex开发、打包、签名、发布

    一.前言      最近有这样一个需求,需要在网页上面启动客户端的软件,软件之间的通信.调用,单单依靠HTML是无法实现了,因此必须借用Activex来实现.由于本人主要擅长C#,自然本文给出了用C# ...

  2. 网页frame引入实现全屏滚动,使用jquery实现浏览器兼容

    近期做一个项目,其中有一个需求,就是网页中需要用frame引入页面并实现frame的全屏,在网上查了好多感觉方式都不尽相同,但是都不是介绍的很全面,浏览器的兼容也做的不好,自己总结了一些要点,需要的可 ...

  3. Java遍历所有网卡打印对应IP

    import java.util.Enumeration; import java.net.*; public class Test { /** * @param args */ public sta ...

  4. 用PLSQL Developer粘贴数据的时候报oracle variant conversion error for variable v0

    参考文章:http://bugcool.blog.51cto.com/2080571/664434 两个数据库表对着copy粘贴的时候,报这个错.只是我这边不是顺序不对,不知道为什么其中的一行换行了. ...

  5. Python Socket,How to Create Socket Server? - 网络编程实例

    文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programin ...

  6. PL/SQL — 函数

    函数通常用于返回特定的数据.其实质是一个有名字的PL/SQL块,作为一个schema对象存储于数据库,可以被反复执行.函数通常被作为一个表达式来调用或存储过程的一个参数,具有返回值.   一.建立函数 ...

  7. 【GPS】 数据围栏

    1.记录gps信息,定位类型  gps  agps ,偏移量 2.根据id检索用户 gps 历史记录 3.创建围栏 4.围栏内用户检索(先实现 圆形和矩形) 5.判断一个点是否进出围栏 应用场景: o ...

  8. [状压dp]HDOJ1565 方格取数(1)

    中文题~~ 题意略 $n\le 20$ ! 很明显是状压! #include <cstdio> #include <cstdlib> #include <cstring& ...

  9. Visual Studio 创建代码注释默认模版方法

    在日常的开发中我们经常需要为页面添加注释和版权等信息,这样我们就需要每次去拷贝粘贴同样的文字,为了减少这种重复性的工作,我们可以把这些信息保存在Visual Studio 2012类库模版文件里 1. ...

  10. [jobdu]从尾到头打印链表

    九度确实烂啊,用cin就超时,必须要scanf.唯一可说的就是pplast和递归打印.也可以用stack,其实和递归一样的空间复杂度. #include<stdio.h> using na ...