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开发艺术探索(三)——View的事件体系
一.View基础知识 主要介绍内容有:View的位置参数.MotionEvent和TouchSlope对象.VelocityTracker.GestureDetector和Scroller对象 1.什 ...
- BABOK - 企业分析(Enterprise Analysis)
BABOK - 企业分析(Enterprise Analysis)概要 发表于2013年10月9日由周金根 描述 企业分析描述我们如何捕捉.提炼并明晰业务需要,并定义一个可能实现这些业务需要的一个方案 ...
- 无法打开SQL Server的连接
机房收费系统重构版的登陆敲了好几天了,总算把登陆窗口敲完了,代码调试的差点儿相同了,问题就处在数据库了. SQL Server配置管理里的SQL Server服务都启动了,可是还是报这个 ...
- FC网络学习笔记02 -网络配置方法
随着新一代飞机的综合化航电系统对通信需求的不断提高,传统的ARINC429.1553B总线的传输速率分别只有100Kbps和1Mbps,其带宽已远远不 论文联盟 http://Www.LWlm.cOm ...
- (linux shell)第一章--小试牛刀(上)
来源:(linux shell)第一章--小试牛刀(上) 从今天開始,我们一起来学习<linux shell脚本攻略>这本书. 1.1简单介绍 shell脚本一般是一个以#!起始的文本文件 ...
- 利用Ajax把前端的数据封装成JSON格式发送到服务器端并写成XML格式在服务器的硬盘上
1.首先要在前端把要发送的东西(这里是一个实例化的car对象)都准备好,利用Ajax发送到服务器端,代码如下: <html xmlns="http://www.w3.org/1999/ ...
- Java的JDBC事务详解(转)
事务的特性: 1) 原子性(atomicity):事务是数据库的逻辑工作单位,而且是必须是原子工作单位,对于其数据修改,要么全部执行,要么全部不执行. 2) 一致性(consistency):事务在完 ...
- 基于Lucene的文件检索Demo
通过Lucene实现了简单的文件检索功能的Demo.这个Demo支持基于文件内容的检索,支持中文分词和高亮显示. 下面简单的介绍下核心的类 1)索引相关的类 1.FileIndexBuilder -- ...
- ajax大数据排队导出+进度条
描述 :我们现在有很多数据,分表存放,现在需要有精度条的导出.最后面有完整源码. 效果图:
- 直接在存储过程里面写sql语句的话 ,会返回操作的结果
ALTER PROCEDURE [dbo].[sp_updateStuStateYRCode] @StuId varchar(100)ASBEGIN update StuState set KM1YR ...