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 ...
随机推荐
- C#中 ThreadStart和ParameterizedThreadStart区别
最主要区别: 1.Thread 是启动一个线程,但是没有参数. 2.ParameterThreadStart 线程可以接受一个输入参数 ThreadStart: ThreadStart这个委托定义为 ...
- OMIM 表型和基因如何关联
OMIM数据库:大神私藏的数据库,99.9%的人都不知道! 2019-03-04 11:00乳腺癌/医生/肺癌 “ GEO.NCDB.TCGA.SEER数据库这些我都知道,但OMIM是什么鬼? OMI ...
- Gson进行json字符串和对象之间的转化
Gson可以实现对象与json字符串之间的转化,以下是在Android中的示例代码. Gson主页:https://code.google.com/p/google-gson/ public clas ...
- leetcode127
class Solution { public int ladderLength(String beginWord, String endWord, List<String> wordLi ...
- discuz 修改积分策略( 在周期中添加"每周" )
在 source/admincp/admincp_credits.php 文件中, ctrl+f 搜索 $lang['setting_credits_policy_cycletype_1'] 处, ...
- VBA 定义能返回数组公式的自定义函数
返回一个变量大小结果数组的方法 此方法返回基于一个参数范围的值的数组.结果数组的大小具体取决于参数数组中的元素数量波动.例如对于假定您要创建一个范围中的每个值乘以 100 的函数.下面的自定义函数接受 ...
- 队列queue实例(生产者和消费者模型)
import queue, threading, time q = queue.Queue(maxsize=10)def producter(n): count = 1 while True: q.p ...
- Mysql canal 监控数据变化
https://www.jianshu.com/p/6299048fad66 阿里巴巴github地址 https://github.com/alibaba/canal/wiki/QuickStart
- python常见异常提示
PEP8 expected 2 blank lines, found 1 定义方法时,出现期望是2个空白行,但是实际检测到是1个.方法与上面内容间隔期望为两个换行符 PEP8 This diction ...
- 【Web缓存机制系列】2 – Web浏览器的缓存机制
Web缓存的工作原理 所有的缓存都是基于一套规则来帮助他们决定什么时候使用缓存中的副本提供服务(假设有副本可用的情况下,未被销毁回收或者未被删除修改).这些规则有的在协议中有定义(如HTTP协议1.0 ...