博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes dfs
阅读量:6826 次
发布时间:2019-06-26

本文共 2084 字,大约阅读时间需要 6 分钟。

D. Bear and Tower of Cubes

题目连接:

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
=p^3要么你就不使用它,使得当前剩余值等于p^3-1,因为只有这样你才用不上p然后dfs去处理就好了

代码

#include
using namespace std;map
>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
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
ans=solve(m); cout<
<<" "<
<

转载地址:http://tuykl.baihongyu.com/

你可能感兴趣的文章
在线预览Word,Excel
查看>>
Exception loading sessions from persistent storage 这个问题的解决
查看>>
python dns server开源列表 TODO
查看>>
Go中的make和new的区别
查看>>
javascript 面向对象编程(工厂模式、构造函数模式、原型模式)
查看>>
最小二乘法多项式拟合的Java实现
查看>>
ubuntu下安装tomcat
查看>>
Excel两列查找重复值
查看>>
纯CSS实现Div高度根据自适应宽度(百分百调整)
查看>>
Azkaban学习之路 (一)Azkaban的基础介绍
查看>>
域名绑定云主机
查看>>
Linux: grep多个关键字“与”和“或”
查看>>
CAS5.2x单点登录(二)cas服务器连接数据库
查看>>
Android tess_two Android图片文字识别
查看>>
高负载微服务系统的诞生过程
查看>>
maven生命周期理解
查看>>
JS基础之传参(值传递、对象传递)
查看>>
(转)几种经典的hash算法
查看>>
Content Security Policy (CSP) 介绍
查看>>
DevExpress去除多国语言包
查看>>