CodeForces 689C Mike and Chocolate Thieves
题目链接: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的更多相关文章
- Codeforces 689C. 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 (二分+数论)
Mike and Chocolate Thieves 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/G Description ...
- 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 (二分)
原题: 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 ...
- codeforces 361 C - Mike and Chocolate Thieves
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Bad ...
- 689C - Mike and Chocolate Thieves 二分
题目大意:有四个小偷,第一个小偷偷a个巧克力,后面几个小偷依次偷a*k,a*k*k,a*k*k*k个巧克力,现在知道小偷有n中偷法,求在这n种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...
随机推荐
- Unity3D 游戏的碰撞
首先创建两个精灵,然后都绑定上碰撞方法(这个是在上一篇文章的基本上): 不过 要注意一点就是碰撞器需要挂一个重力组件,不然无效 所以添加了差不多就能够实现物体碰撞了: 接下来技术写代码,让碰撞的时候进 ...
- 关于一点coding.net与git配合在AndroidStudio/Idea上的使用笔记个的
编写程序的我们经常需要对我们写的代码做版本控制,或者分支管理,具备类似功能的软件很多,诸如SVN,Git,CVS等等!但配置版本控制服务器(SVN server etc.)是繁琐的并且需要一定的成本! ...
- rdlc报表
也是第一次接触报表这个东西.现在在我理解,报表无非就是两个内容,格式和数据. 格式没有多少了解,就记录了,以后再续.数据的绑定和结果的显示是怎么实现的呢? 今天的主角就是rdlc这个文件和Report ...
- ActionScript:Resampling PCM data
使用基于flash的麦克风录音,如果想在获取完PCM采样数据后,通过Sound马上回放,必须经过resampling.(注意:如果录音是采用的44KHz的话,则不需要) 因此,需要as实现一个简便的函 ...
- iOS-NSSDate的使用
取当前时间的秒数 NSTimeInterval time = [[NSDate date] timeIntervalSince1970];long long int date = (long long ...
- 用layer添加UIView的动画
项目有时会遇到用UIView 添加动画的情况,这里我觉得在layer上添加动画比较好,因为可以详细地设定动画属性,方便理解 下面是一个旋转动画: -(void)roundBtnAction:(id)s ...
- weChat聊天发送图片带有小尖角的实现
weChat聊天发送图片带有小尖角的实现 1.#import <UIKit/UIKit.h>2.3.@interface JKShapeImage : UIView4.5.@propert ...
- Android 新版NDK环境搭建(免Cygwin)
使用最新ndk,直接抛弃cygwin,以前做Android的项目要用到NDK就必须要下载NDK,下载安装Cygwin(模拟Linux环境用的),下载CDT(Eclipse C/C++开发插件),还要配 ...
- Kickstart + http Linux自动化部署服务端
设备需要开启Network Boot功能.具体PXE技术就另外提,本文主要讲解配置. 在搭建该服务器之前需要关闭SELinux和iptables不然可能dhcp服务都起不来,客户端收不到IP地址,无法 ...
- YII 验证功能
YII 表单的验证可以在module目录下的xxx.php里面定义验证方法,设定需要验证的字段就行 //用户表单验证,在模型里面设置一个方法,具体表单验证规则 public functi ...