codeforces 361 C - Mike and Chocolate Thieves
Description
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly k times more than the previous one. The value of k (k > 1) is a secret integer known only to them. It is also known that each thief's bag can carry at most n chocolates (if they intend to take more, the deal is cancelled) and that there wereexactly four thieves involved.
Sadly, only the thieves know the value of n, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed n, but not fixed k) is m. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of n will help him in that. Please find the smallest possible value of n or tell him that the rumors are false and there is no such n.
Input
The single line of input contains the integer m(1 ≤ m ≤ 1015) — the number of ways the thieves might steal the chocolates, as rumours say.
Output
Print the only integer n — the maximum amount of chocolates that thieves' bags can carry. If there are more than one n satisfying the rumors,print the smallest one.
If there is no such n for a false-rumoured m, print - 1.
Sample Input
1
8
8
54
10
-1
Hint
In the first sample case the smallest n that leads to exactly one way of stealing chocolates is n = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest n that leads to exactly 8 ways is n = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).
There is no n leading to exactly 10 ways of stealing chocolates in the third sample case.
题意:四个小偷想偷巧克力。偷得方案符合如下规则:
巧克力无数,但小偷们的背包容量固定为n(每个小偷最多偷n块巧克力
第一个小偷随意拿,之后三个小偷按照签一个小偷的倍数拿,保证倍数一定。
譬如 1,2,4,8,第一个拿1块,之后每人拿前一人的二倍。 倍数>1
给出方案数目,问背包容量n为多少可以偷出这么多方案。
如果有多解,输出最少的背包容量。
分析:
先二分背包容量,
再枚举倍数的话,其实对于已知容量n,已知倍数x下。
能偷得方案数其实就是n/x 自然取整即可(求出此时的方案数)
方案数跟m比较 ,然后继续二分。
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long L=,R=1e16;
long long check(long long m)
{
long long sum=;
for(long long i=;;i++)
{
if(m>=i*i*i)
sum+=m/(i*i*i);
}
return sum;
}
int main()
{
long long n,mid,s,ans=-;;
scanf("%lld",&n);
while(L<=R)
{
mid=(L+R)/;
s=check(mid);
if(s==n) ans=mid;
else if(s>=n) R=mid-;
else L=mid+;
}
cout<<ans<<endl;
return ;
}
codeforces 361 C - Mike and Chocolate Thieves的更多相关文章
- codeforces 689C C. Mike and Chocolate Thieves(二分)
题目链接: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabyte ...
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...
- Codeforces 689C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- Codeforces Round #341 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- CodeForces 689C Mike and Chocolate Thieves (二分)
原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...
- CodeForces 689C Mike and Chocolate Thieves
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145 题目大意:给定一个数字n,问能不能求得一个最小的整 ...
- CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)
题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...
- codeforces 361 E - Mike and Geometry Problem
原题: Description Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him ...
随机推荐
- Android基础知识回顾
- xml基础学习笔记
1 XML入门 1.1 引入 HTML: 负责网页的结构 CSS: 负责网页的样式(美观) Javascript: 负责在浏览器端与用户进行交互. 负责静态的网页制作的语言 HTML语言特点: 1)由 ...
- Hibernate学习之表一对多,多对一关系
代码: person类: public class Person { private long id; private String name; private int age; private Da ...
- 几个shell自动化脚本(定期清理、磁盘空间、搜寻关键字)
发布时间:2014-10-28 09:52:17 编辑:AHLinux.com 分享几个精致耐用的shell脚本,分别用于定期清理暂存文件.检查硬盘空间使用率.搜寻所有记录文件的关键字符串.有需要 ...
- 在mysql中修改表名的sql语句
在使用mysql时,经常遇到表名不符合规范或标准,但是表里已经有大量的数据了,如何保留数据,只更改表名呢?可以通过建一个相同的表结构的表,把原来的数据导入到新表中,但是这样视乎很麻烦.能否简单使用一个 ...
- Excel中如何查找并列出所有链接(外部数据链接)?
在 Excel 中,有时会需要创建外部链接来引用其他工作簿的单元格内容,但是如果想要找出所有链接并且还要将这些外部数据链接列在一个工作簿当中是有点难度的.下面我会介绍一些快捷方法,不仅能够快速帮你找出 ...
- FastDFS分布文件系统[转]
FastDFS是为互联网应用量身定做的一套分布式文件存储系统,非常适合用来存储用户图片.视频.文档等文件.对于互联网应用,和其他分布式文件系统相比,优势非常明显.具体情况大家可以看相关的介绍文档,包括 ...
- 追踪CPU跑满 堆栈调试
http://blog.donghao.org/2014/04/24/%E8%BF%BD%E8%B8%AAcpu%E8%B7%91%E6%BB%A1/
- Android(java)学习笔记189:eclipse 导入项目是提示:某些项目因位于工作空间目录中而被隐藏。
导致这个错误的原因是工程重名了: 并不是仅仅指文件夹重名,相信很多人也曾经修改过文件夹的名称,可惜没什么用处,关键是修改工程里面的一个文件!也就是.project这个文件! 用记事本打开,修改一下&l ...
- exists查询中子表可以是
exists查询中子表可以是’或则具体某一列 ,查询结果一致,因为exists只会返回 true或者false,一个boolean型的值