CodeForces 287B Pipeline (水题)
2 seconds
256 megabytes
standard input
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.
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.
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.
4 3
2
5 5
1
8 4
-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 (水题)的更多相关文章
- Codeforces数据结构(水题)小结
最近在使用codeblock,所以就先刷一些水题上上手 使用codeblock遇到的问题 1.无法进行编译-------从setting中的编译器设置中配置编译器 2.建立cpp后无法调试------ ...
- CodeForces 705A Hulk (水题)
题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240 ...
- CodeForces 705B (训练水题)
题目链接:http://codeforces.com/problemset/problem/705/B 题意略解: 两个人玩游戏,解数字,一个数字可以被分成两个不同或相同的数字 (3可以解成 1 2) ...
- codeforces hungry sequence 水题
题目链接:http://codeforces.com/problemset/problem/327/B 这道题目虽然超级简单,但是当初我还真的没有想出来做法,囧,看完别人的代码恍然大悟. #inclu ...
- codeforces 377A. Puzzles 水题
A. Puzzles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/33 ...
- CodeForces 474B Worms (水题,二分)
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里. 析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound. 代码如下: #include<bits/stdc+ ...
- CodeForces - 682B 题意水题
CodeForces - 682B Input The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — ...
- CodeForces 709A Juicer (水题, 模拟)
题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pra ...
- CodeForces 707B Bakery (水题,暴力,贪心)
题意:给定n个城市,其中有k个有仓库,问你在其他n-k个城市离仓库的最短距离是多少. 析:很容易想到暴力,并且要想最短,那么肯定是某一个仓库和某一个城市直接相连,这才是最优,所以只要枚举仓库,找第一个 ...
随机推荐
- 【BZOJ3110】[Zjoi2013]K大数查询 树套树
[BZOJ3110][Zjoi2013]K大数查询 Description 有N个位置,M个操作.操作有两种,每次操作如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c,如果 ...
- 【BZOJ4514】[Sdoi2016]数字配对 费用流
[BZOJ4514][Sdoi2016]数字配对 Description 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ...
- redis自启动
$ vi /etc/init.d/redis # chkconfig: 2345 90 10 # description: Redis is a persistent key-value databa ...
- 大家都是怎么看待STO的?
STO,全称为「Security Token Offer」,即证券型通证发行.STO是2017年底从美国开始流行的,对于在美国注册的公司,STO是一个合法合规的ICO. 对于STO,大家都是怎么看待的 ...
- API的理解和使用——集合
集合类型的命令及时间复杂度 区间 命令 功能 时间复杂度 集合内 sadd key element [element ... ] 添加元素 O(k),k是元素个数 srem key elemen ...
- [2018-11-03]2018年10月28日宁波dotnet社区活动回顾及下次活动预告
离上次活动,有半年了,汗.之后尽量保证每月一次,以组织为主,多邀请嘉宾来分享. 本次活动不足之处 人手不足:由于活动组织事项受限于人手(目前就我一个,这次活动前后我又应邀给大红鹰学院应届生介绍dotn ...
- LeetCode:N叉树的最大深度【559】
LeetCode:N叉树的最大深度[559] 题目描述 给定一个N叉树,找到其最大深度. 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数. 例如,给定一个 3叉树 : 我们应返回其最大深度, ...
- Java基础教程:对象比较排序
Java基础教程:对象比较排序 转载请标明出处:http://blog.csdn.net/wangtaocsdn/article/details/71500500 有时候需要对对象列表或数组进行排序, ...
- 4.Web工程师的开发工具箱
第四章 效率工具ShadowSocks window代理服务器FalconProxy chrome代理服务器stackoverflow.com Stack Overflow是一个与程序相关的IT技术问 ...
- 学习c语言的第14天
#include <stdio.h> #include <string.h> struct student { int age; char sex; char name[100 ...