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种偷法中偷得最多的小偷的所偷的最小值. 题目思路:二分查找偷 ...
随机推荐
- NetworkOnMainThreadException
来自:http://www.2cto.com/kf/201402/281526.html NetworkOnMainThreadException extends RuntimeException j ...
- reflact中GetMethod方法的使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- Alljoyn 概述(1)
Alljoyn Overview Feb. 2012- AllJoyn 是什么? • 2011年2月9日发布,由 QuiC(高通创新中心)开发维护的开源软 件项目,采用 Apache license ...
- JavaScript Window - 浏览器对象模型
浏览器对象模型 (BOM) 使 JavaScript 有能力与浏览器"对话". 浏览器对象模型 (BOM) 浏览器对象模型(Browser Object Model (BOM))尚 ...
- 使用highlight.js高亮你的代码
在逛别人的博客的时候,看见别人的代码的例子使用了高亮的语法,无论是java,js还是php等等语言,都会自动的对关键字进行高亮. 于是在前几天自己写了一个博客,遇到code时,自然就想到了别人网站如何 ...
- [转]Delphi调用cmd的两种方法
delphi调用cmd的两种方法vars:string;begins:='cmd.exe /c '+edit1.Text+' >c:\1.txt';winexec(pchar(s),sw_hid ...
- C蛮的全栈之路-序章 技术栈选择与全栈工程师
目录 C蛮的全栈之路-序章 技术栈选择与全栈工程师C蛮的全栈之路-node篇(一) 环境布置C蛮的全栈之路-node篇(二) 实战一:自动发博客 博主背景 985院校毕业,至今十年C++开发工作经验, ...
- 解决js浮点数计算bug
1.加 function add(a, b) { var c, d, e; try { c = a.toString().split(".")[1].length; } catch ...
- POJ 1830.开关问题(高斯消元)
题目链接 Solutin: 将每个开关使用的情况当成未知数,如果开关i能影响到开关j,那么系数矩阵A[j][i]的系数为1. 每个开关增广矩阵的值是开关k的初状态异或开关k的目标状态,这个应该很容易想 ...
- javascript——面向对象程序设计(3)
<script type="text/javascript"> //1.结合使用构造函数模式和原型模式 //2.动态原型模式 //3.寄生构造函数模式 //4.稳妥构造 ...