B. Pipeline
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.

A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.

The figure shows a 4-output splitter

Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.

Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.

Input

The first line contains two space-separated integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 109).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Output

Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.

Sample test(s)
input
4 3
output
2
input
5 5
output
1
input
8 4
output
-1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <stack>
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,n) for(i=1;i<=(n);++i)
using namespace std;
typedef long long ll;
const int INF = <<;
const double eps = 1e-;
const int N = ; void show(int *arr,int l,int r)
{
for(int i=l;i<r;++i)
{
printf("%d ",arr[i]);
if(i%==) cout<<endl;
}
} long long n,k; ll get(double x)
{
double aa = floor(x+0.5);
if(fabs(x-aa)<eps) return (ll)aa;
return (ll)ceil(x);
} void run()
{
if(n==)
{
cout<<""<<endl;
return;
}
if(n==)
{
cout<<""<<endl;
return;
}
if((+k)*(k-)/-(k-)<n)
{
cout<<"-1"<<endl;
return;
}
if(n<=k)
{
cout<<""<<endl;
return;
}
else if(n<=k+k-)
{
cout<<""<<endl;
return;
}
double a,b,c;
a=1.0;
b=-*k+;
c=*n-;
double de=sqrt(b*b-*a*c);
// double ans1 = (-b+de)/(2*a);
double ans2 = (-b-de)/(*a);
// cout<<ans2<<endl;
ll ans = get(ans2);
// cout<<ans1<<' '<<ans2<<endl;
cout<<ans<<endl;
} int main()
{
// double x;
// while(cin>>x) cout<<get(x)<<endl;
while(cin>>n>>k)
run();
return ;
}

CodeForces 287B Pipeline (水题)的更多相关文章

  1. Codeforces数据结构(水题)小结

    最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...

  2. CodeForces 705A Hulk (水题)

    题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240 ...

  3. CodeForces 705B (训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/B 题意略解: 两个人玩游戏,解数字,一个数字可以被分成两个不同或相同的数字 (3可以解成 1 2) ...

  4. codeforces hungry sequence 水题

    题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...

  5. codeforces 377A. Puzzles 水题

    A. Puzzles Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...

  6. CodeForces 474B Worms (水题,二分)

    题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...

  7. CodeForces - 682B 题意水题

    CodeForces - 682B Input The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — ...

  8. CodeForces 709A Juicer (水题, 模拟)

    题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pra ...

  9. CodeForces 707B Bakery (水题,暴力,贪心)

    题意:给定n个城市,其中有k个有仓库,问你在其他n-k个城市离仓库的最短距离是多少. 析:很容易想到暴力,并且要想最短,那么肯定是某一个仓库和某一个城市直接相连,这才是最优,所以只要枚举仓库,找第一个 ...

随机推荐

  1. NDK以及C语言基础语法(一)

    一.什么是NDK? Native Development Kit (本地开发工具包): NDK中提供了一系列的工具,帮助我们快速开发C/C++的动态库,并能自动将so文件和java文件一起打包成apk ...

  2. MySQL集群搭建

    在集群中的所有主机上安装提供集群功能的软件包 官网上下载的  mysql-cluster-gpl-7.3.12-linux-glibc2.5-x86_64.tar.gz 规划了5台服务器,10.10. ...

  3. Vue中表单校验

    1.安装校验插件vee-validate npm install vee-validate --save 2.在main.js中引用插件 // 表单校验 import VeeValidate, { V ...

  4. var foo = "11"+2+"1"; console.log(foo); //1121 好多文章答案写错了,我发下给初学的朋友看到,以免一开始就学错了

    体会加一个字符串'1' 和 减去一个字符串'1'的不同 var foo = "11"+2-"1"; console.log(foo); //111 consol ...

  5. 【题解】Sumdiv

    [题解]Sumdiv 传送门 根据组合的乘法原理,一个数的所有约数和 \[ sum=\prod_{i=1} \Sigma_j^{a_i} p_i^j \] 所以任务就变成了分解\(A\)的质因数,分解 ...

  6. mysql 查看或者修改数据库密码

    首先启动命令行 1.在命令行运行:taskkill /f /im mysqld-nt.exe 下面的操作是操作mysql中bin目录下的一些程序,如果没有配置环境变量的话,需要切换到mysql的bin ...

  7. Ruby 打印

    puts: 输出内容自动换行,转义后再输出(转义符),可传递多个参数puts("this is ge num=",a,"this is b=",b)   pri ...

  8. oracle ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

    ORA-12514: TNS:listener does not currently know of service requested in connect descriptor 1.看看是不是监听 ...

  9. <密码学入门>关于DES加密算法解密算法相关问题

    题外话:个人觉得DES加密解密真的是一种过程冗长的方法,S盒,P盒还有各种各样的变换让人眼花缭乱. (一)Feistel密码结构 要先说Feistel密码结构的原因是DES加密过程是和Feistel密 ...

  10. 9.1 NOIP普及组试题精解(3)

    9-6 seat.c #include <stdio.h> #define MAXN 1001 void swap(int *a, int *b) //交换数据 { int t; t = ...