Codeforces 689C. Mike and Chocolate Thieves 二分
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 were exactly 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.
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.
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.
1
8
8
54
10
-1
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.
题目链接:http://codeforces.com/contest/689/problem/C
题意:有4个小偷偷东西,后面一个偷的是前面一个的K倍。有m种可能性,每个小偷偷的东西不能超过一个容量,求小偷的最小的容量n。
思路:假设容量为x,则可能性有cou=x/(2^3)+x/(3^3)+x/(4^3)+.....种。暴力二分求x。二分次数最多为64次,每一次最多进行10^6求cou,与m进行判断比较。
代码:
#include<bits/stdc++.h>
using namespace std;
__int64 gg[];
int main()
{
__int64 i,m;
for(i=; i<=; i++)
gg[i]=i*i*i;
scanf("%I64d",&m);
__int64 l=,r=1e18,mid;
int flag=;
__int64 ans;
while(l<r)
{
mid=(l+r)>>;
__int64 cou=;
for(i=; gg[i]<=mid; i++)
cou+=mid/gg[i];
cout<<l<<" "<<r<<" "<<mid<<" "<<cou<<endl;
if(cou>m) r=mid-;
else if(cou<m) l=mid+;
else
{
r=mid;
flag=;
ans=mid;
}
}
if(flag) cout<<ans<<endl;
else cout<<"-1"<<endl;
return ;
}
Codeforces 689C. Mike and Chocolate Thieves 二分的更多相关文章
- CodeForces 689C Mike and Chocolate Thieves (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- 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 (二分最大化最小值)
题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...
- 689C - Mike and Chocolate Thieves 二分
题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...
- 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 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
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145 题目大意:给定一个数字n,问能不能求得一个最小的整 ...
- codeforces 361 C - Mike and Chocolate Thieves
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Bad ...
随机推荐
- 函数图 https://www.processon.com/mindmap/5b5077fae4b040415ae39c64
---恢复内容结束---
- linux更换shell外壳zsh
linux-外壳内核与shell的关系 内核处于外壳之中,通过外壳与shell(命令行)交互 外壳可以更换 ############################################## ...
- UVA-712-满二叉树
一个策略树(S-tree)是一组变量Xn={x1,x2...xn}的表现形式,它代表一个布尔函数f:{0,1}n->{0,1},策略树每条路径从根结点开始由n+1个结点组成,策略树的每一个结点都 ...
- 《汇编语言 基于x86处理器》前五章的小程序
▶ 书中前五章的几个小程序,基本的运算操作,使用了作者的库 Irvine32 和 Irvine64(一开始以为作者网站过期了,各网站上找到的文件大小都不一样,最后发现是要搭梯子 Orz,顺利下载).注 ...
- zabbixzabbix
一,安装文档 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements zabbix3.2.6安装 ...
- redis详解(三)
1. 使用redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...
- Activity服务类-6 ManagementService服务类
一共含有17个方法 // 获取包含了Activiti数据库模式的{表名.行计数}项的映射.Map<String, Long> getTableCount();//获取诸如任务.执行之类的A ...
- Eclipse 工程使用相对路径导入Jar包设置
环境:MyEclipse 6.5 问题:MyEclipse 工程使用相对路径导入Jar包 我们在导入工程时,往往添加Jar都是使用的绝对路径,但这带来了一个问题,不同的用户使用工程都得重新配置Buil ...
- keras图像预处理-ImageDataGenerator
相关参数描述:http://keras-cn.readthedocs.io/en/latest/preprocessing/image/其中validation_split参数(官方上使用方法未描述) ...
- hadoop配置文件的参数含义说明
#hadoop version 查看版本号 1 .获取默认配置 hadoop2系列配置文件一共包括6个,分别是hadoop-env.sh.core-site.xml.hdfs-site.xml.map ...