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 ...
随机推荐
- express基础
express框架 const express = require("express"); 引入express框架 var app= express(); 实例化 相当于构造函 ...
- mysql各种连接总结
术语解释: 1.内连接: 只连接匹配的行 2.左外连接: 包含左边表的全部行(不管右边的表中是否存在与它们匹配的行),以及右边表中全部匹配的行 3.右外连接: 包含右边表的全部行(不管左边的表中是否存 ...
- jquery函数写法
普通jquery函数写法 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script&g ...
- zabbixzabbix
一,安装文档 https://www.zabbix.com/documentation/4.0/zh/manual/installation/requirements zabbix3.2.6安装 ...
- Java实现邮箱发送
- http get 方式参数的长度限制<转>
http get 方式参数的长度限制 这个问题一直以来似乎是被N多人误解,其实Http Get方法提交的数据大小长度并没有限制,而是IE浏览器本身对地址栏URL长度有最大长度限制:2048个字符. 当 ...
- 11 并发编程-(线程)-信号量&Event&定时器
1.信号量(本质也是一把锁)Semaphore模块 信号量也是一把锁,可以指定信号量为5,对比互斥锁同一时间只能有一个任务抢到锁去执行, 信号量同一时间可以有5个任务拿到锁去执行, 如果说互斥锁是合租 ...
- UI5-文档-4.27-Mock Server Configuration
我们只是在一个真实的服务上运行我们的应用程序,但是对于开发和测试我们的应用程序,我们不希望依赖于“真实”服务的可用性,或者在数据服务所在的系统上增加额外的负载. 这个系统就是所谓的后端系统,我们现在将 ...
- 两个关于URL解析的例子
例一: /* 解析URL查寻串中的name=value参数对 将name=value对存储在对象属性中,并返回对象 alert(getQuery().name) */ function getQuer ...
- Mysql binlog二进制日志
Mysql binlog日志有三种格式,分别为Statement,MiXED,以及ROW! 1.Statement:每一条会修改数据的实际原sql语句都会被记录在binlog中. 优点:不需要记录每一 ...