Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs
D. Bear and Tower of Cubes
题目连接:
http://www.codeforces.com/contest/680/problem/D
Description
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.
Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.
Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
Input
The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.
Output
Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.
Sample Input
48
Sample Output
9 42
Hint
## 题意
有一个人在玩堆积木的游戏,给你一个X,这个人会贪心选择一个最大的数,使得这个数a^3<x,然后堆上去,x-=a^3
然后一直重复这个过程,
现在给你一个m,你需要在[1,m]里面找到最大的x,使得使用的数最多,在使用的数最多的情况下,这个数尽量大
-----------------------------------
## 题解:
直接dfs,每次你有两种决策
要么你就使用当前可用的满足x>=p^3
要么你就不使用它,使得当前剩余值等于p^3-1,因为只有这样你才用不上p
然后dfs去处理就好了
代码
#include<bits/stdc++.h>
using namespace std;
map<long long ,pair<int ,long long> >H;
long long getmax(long long x)
{
if(x==1)return 1;
long long l=1,r=100005,ans=1;
while(l<=r)
{
long long mid = (l+r)/2LL;
if(mid*mid*mid<=x)ans=mid,l=mid+1;
else r=mid-1;
}
return ans;
}
pair<int,long long> solve(long long x){
if(x==0)return make_pair(0,0);
if(H.count(x))return H[x];
auto &tmp = H[x];
long long p = getmax(x);
tmp=solve(x-p*p*p);
tmp.first++;
tmp.second+=p*p*p;
auto tmp2 = solve(p*p*p-1);
tmp=max(tmp,tmp2);
return tmp;
}
void QAQ()
{
long long m;scanf("%lld",&m);
pair<int,long long>ans=solve(m);
cout<<ans.first<<" "<<ans.second<<endl;
}
int main()
{
QAQ();
}
Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs的更多相关文章
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100(转)
C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)
B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Codeforces Round #356 (Div. 2)A. Bear and Five Cards(简单模拟)
A. Bear and Five Cards time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #356 (Div. 1) D. Bear and Chase 暴力
D. Bear and Chase 题目连接: http://codeforces.com/contest/679/problem/D Description Bearland has n citie ...
- Codeforces Round #356 (Div. 2) E. Bear and Square Grid 滑块
E. Bear and Square Grid 题目连接: http://www.codeforces.com/contest/680/problem/E Description You have a ...
- Codeforces Round #356 (Div. 2) C. Bear and Prime 100 水题
C. Bear and Prime 100 题目连接: http://www.codeforces.com/contest/680/problem/C Description This is an i ...
- Codeforces Round #356 (Div. 2) B. Bear and Finding Criminal 水题
B. Bear and Finding Criminals 题目连接: http://www.codeforces.com/contest/680/problem/B Description Ther ...
- Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题
A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little be ...
- Codeforces Round #356 (Div. 1) C. Bear and Square Grid
C. Bear and Square Grid time limit per test 3 seconds memory limit per test 256 megabytes input stan ...
随机推荐
- Python中使用LMDB
在python中使用lmdb linux中,可以使用指令pip install lmdb安装lmdb包. 生成一个空的lmdb数据库文件 # -*- coding: utf-8 -*- import ...
- 【Andorid开发框架学习】之Volley入门
Volley是Android平台上的网络通信库,能使网络通信更快,更简单,更健壮.Volley特别适合数据量不大但是通信频繁的场景.在listView显示图片这方面,使用volley也是比较好的,不必 ...
- 打造 Laravel 优美架构 谈可维护性与弹性设计
转载:https://juejin.im/post/5be4475c518825170559c044
- python去除html空格
如下面的 <td> 柳暗花溟</td> html里面的空格 ,想直接用strip()函数去除是不可能的,必须显式的去掉\xa0 例如以上的就可以这样的方式去除空 ...
- Python模块制作
在Python中,每个Python文件都可以作为一个模块,模块的名字就是文件的名字. 定义自己的模块 比如有这样一个文件test.py,在test.py中定义了函数add def add(a,b): ...
- JAVA随笔(二)
在函数传参时,double传给int是不行的,反过来可以.参数只能传值.当参数是字符串时,传递的只是串值:但对于数组来说,传递的是管理权,也就是指针 对象变量是对象管理者. cast转型:基本类型与对 ...
- 本地为Windows,使用Xshell登录Linux云主机
以某东的云主机为实例 1. 下载并安装远程登录软件 下载Xshell软件 下载后双击xshell5_5.0.1332.exe进行安装 2. 安装完成,打开Xshell,并点击新建,根据要求输入相应参数 ...
- wpf 查找 子元素
RightContainer.ApplyTemplate();//如果找不到,就执行该句试一试 var xxx=UIHelper.FindChild<ScrollViewer>(Right ...
- 嵌入式 探讨父子线程、进程终止顺序不同产生的结果_skdkjxy_新浪博客
嵌入式 探讨父子线程.进程终止顺序不同产生的结果 Linux下编程,线程.进程退出顺序问题纷纷扰扰,如果父进程/线程先于子进程/线程终止,系统会做什么处理呢?反之,如果子进程/线程先于父进程/线 程终 ...
- (一)问候MyBatis3
第一节:MyBatis简介 百度百科 第二季:Mybatis版HolleWorld实现 例子: mybatis-config.xml: <?xml version="1.0" ...