题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412145

题目大意:给定一个数字n,问能不能求得一个最小的整数x,使得在1-x范围内,可以取的n组T*k^3<=x。T,k为任意整数,需要在小于等于x的情况下,凑够n对T,k,使其满足T*k^3<=x。若x存在,则输出x,若x不存在,则输出-1。

解题思路:

先看k=2,(1,2,4,8)/(2,4,8,16)/(3,6,12,24)....

k=3,(1,3,9,27)/(2,6,18,54)......

对应某个k,在x范围内,其能取到的最大组数为x/(k^3),因为合法组数具有单调性,可以采用二分的方法求解。

两种情况很好理解,当当前数量已大于要求数量,那便移动右边界,当当前数量小于要求数量,则移动左边界,但相等时,并不一定就是解。因为,题目要求是合法时最小的整数解,故而继续移动右边界。

解题代码:

#include <cstdio>
#include <iostream>
using namespace std;
#define ll long long
ll solve(ll n)
{
ll ans=;
for(ll i=;;i++)
{
if(n/(i*i*i)==) break;
ans+=n/(i*i*i);
}
return ans;
}
int main()
{
ll m;
cin>>m;
int flag=;
ll l=,r=5e15,ans;
while(l<=r)
{
ll mid=(l+r)/;
long long cnt=solve(mid);
if(cnt>m) r=mid-;
else if(cnt<m) l=mid+;
else
{
ans=mid;
flag=;
r=mid-;
}
}
printf("%lld\n",flag?ans:-);
return ;
}

CodeForces 689C  Mike and Chocolate Thieves的更多相关文章

  1. Codeforces 689C. Mike and Chocolate Thieves 二分

    C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...

  2. CodeForces 689C Mike and Chocolate Thieves (二分+数论)

    Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...

  3. codeforces 689C C. Mike and Chocolate Thieves(二分)

    题目链接: C. Mike and Chocolate Thieves time limit per test 2 seconds memory limit per test 256 megabyte ...

  4. 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 ...

  5. 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 ...

  6. CodeForces 689C Mike and Chocolate Thieves (二分)

    原题: Description Bad news came to Mike's village, some thieves stole a bunch of chocolates from the l ...

  7. CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)

    题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...

  8. codeforces 361 C - Mike and Chocolate Thieves

    Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u   Description Bad ...

  9. 689C - Mike and Chocolate Thieves 二分

    题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...

随机推荐

  1. 移动web设计稿尺寸,关于移动web尺寸的那点事

    我自己的做稿子的时候,一开始就有一个习惯,先放上这段代码<meta name="viewport" content="width=device-width, ini ...

  2. 调优系列-tomcat调优

    http://www.360doc.com/content/14/1208/13/16070877_431273418.shtml 使用JMeter对Tomcat进行压力测试与Tomcat性能调优 n ...

  3. mac下开发环境常用操作与命令

    [1] 修改hosts文件 vim /private/etc/hosts

  4. Android开发app如何设定应用图标下的应用名称为汉字以及自定义图标

    一.应用名称为汉字 二.自定义图标

  5. C# Activator.CreateInstance()

    C#在类工厂中动态创建类的实例,所使用的方法为: 1. Activator.CreateInstance (Type) 2. Activator.CreateInstance (Type, Objec ...

  6. [转帖]音响及DarBee

    红外与蓝牙的差别 1.距离 红外:对准.直接.1—2米,单对单 红外线可以用你的手机摄像头看到  蓝牙:10米左右,可加强信号,可以绕弯,可以不对准,可以不在同一间房间,链接最大数目可达7个,同时区分 ...

  7. Sqoop import加载HBase过程中,遇到Permission denied: user=root, access=WRITE, inode="/user":hdfs:supergroup:drwxr-xr-x

    在执行hbase sqoop抽取的时候,遇到了一个错误,如下图: 在执行程序的过程中,遇到权限问题很正常,也容易让人防不胜防,有问题就想办法解决,这个是关键. 解决办法如下: 第一步:su hdfs, ...

  8. js实现滑动解锁功能(PC+Moblie)

    http://dummyimage.com/600x400/ http://placehold.it/140x70 实现效果: css样式代码略. html代码: 页面上导入了jquery.mobil ...

  9. 在静态页面html中跳转传值

    在html中通过"?"传值--------<a href="index2.html?name=caoy">静态传值</a> 在跳转到的页 ...

  10. unix环境高级编程-读书笔记与习题解答-第一篇

    从这周开始逐渐的进入学习状态,每天晚上都会坚持写c程序,并且伴随对这本书的深入,希望能写出更高质量的读书笔记和程序. 本书的第一章,介绍了一些关于unix的基础知识,在这里我不想去讨论linux到底是 ...