题目链接: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. 学点bootstrap

  2. 自定义Window 服务

    自定义window 服务 开发到使用的流程: 1.完成对应的代码之后(代码在底下),右键MyService.cs 添加安装程序 2.添加window服务安装程序打开Service1.cs[设计]页面, ...

  3. 获取Android studio中的SHA1

    因为想要弄一下百度地图. 然后要申请一个key. 需要SHA1. 按window键 +R 输入cmd 进入C:\Users\Administrator路径 输入cd .android,进行.andro ...

  4. 使用ng-if,获取不到里面的ng-model值,解决方案

    当使用ng-if时,是会把默认作用域删除的,当其为true时,只是增加了其界面元素,为最原始状态,控制器在其上是不起作用的,要想获取ng-if中的值,可以用$scope.$$childTail.lay ...

  5. PictureBox内的图片拖动功能

    当 PictureBox内的图片太大,超过PictureBox边框时可以用下面的方法来实现,   通过重绘来实现 :   Code bool wselected = false;  Point p = ...

  6. swfupload上传文件问题

    如果你的框架用到了struts2的话  可能会造成request冲突    那么解决的办法就是把该request排除出去  不让struts2拦截

  7. thinksns消息提示的实现机制(转)

    转自:http://jingyan.baidu.com/article/f25ef2541718eb482c1b8215.html thinksns的消息提示不是实时的,而是1分钟向服务器请求一次,再 ...

  8. javascript中的基本数据类型

    在javascipt中有五大基本数据类型,列表如下: 1.数字 他们又又包括(正负整数,浮点数)十进制数,十六进制数与八进制数,指数和特殊数值NaN,(Infinity,-Infinity)正负无穷 ...

  9. Apache与php的整合(经典版),花了一天去配置成功经验

    1.首先在官方下载php-7.0.7-Win32-VC14-x64.zip和httpd-2.4.20-win64-VC14.zip,也可以下载镜像版的apache:apache_2.4.4-x64-o ...

  10. php多条件组合查询

    1. 通过表单把查询条件提交到php文件中,在文件中以post的形式得到传送过来的条件. 2. 把传过来的查询条件赋给变量. 3. 判断如果查询条件非空,则拼接查询sql. 大体如下: 1. < ...