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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 一个脚本和一个容易疏忽的问题strcmp、strncmp、memcmp的用法【原创】

    一个容易疏忽的问题: strcmp.strncmp.memcmp, 对于memcmp进行字符串比较时可能会出现内存重叠的情况 status = strncmp(xdev->product, &q ...

  2. MySQL分布式集群之MyCAT(一)简介【转】

    隔了好久,才想起来更新博客,最近倒腾的数据库从Oracle换成了MySQL,研究了一段时间,感觉社区版的MySQL在各个方面都逊色于Oracle,Oracle真的好方便!好了,不废话,这次准备记录一些 ...

  3. nginx自定义500,502,504错误页面无法跳转【转】

    1.自定一个页面,这个页面是一个链接地址可以直接访问的. 以下是nginx的配置: location / {            proxy_pass http://tomcat_app108;   ...

  4. 关于oracle数据库死锁的检查方法

    一.数据库死锁的现象程序在执行的过程中,点击确定或保存按钮,程序没有响应,也没有出现报错. 二.死锁的原理当对于数据库某个表的某一列做更新或删除等操作,执行完毕后该条语句不提交,另一条对于这一列数据做 ...

  5. C# 调用WSDL接口及方法

    1.首先需要清楚WSDL的引用地址 如:http://XX.XX.4.146:8089/axis/services/getfileno?wsdl 上述地址的构造为 类名getfileno. 2.在.N ...

  6. STL容器 vector,list,deque 性能比较

    C++的STL模板库中提供了3种容器类:vector,list,deque对于这三种容器,在觉得好用的同时,经常会让我们困惑应该选择哪一种来实现我们的逻辑.在少量数据操作的程序中随便哪一种用起来感觉差 ...

  7. 洛谷P3385负环

    传送门 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...

  8. 洛谷P1725 琪露诺

    传送门啦 本人第一个单调队列优化 $ dp $,不鼓励鼓励? 琪露诺这个题,$ dp $ 还是挺好想的对不,但是暴力 $ dp $ 的话会 $ TLE $ ,所以我们考虑用单调队列优化. 原题中说她只 ...

  9. 如何查看K8S的网络是否完好

    今天工作中遇到这个问题, 检查从以下几个方面入手. 一,查看各个POD的LOG,如果有错误,则要解决了再继续 二,登陆各个POD之间,互相要能PING通. 三,在物理节点上可以PING通SERVICE ...

  10. rocketmq在linux上安装

    1.下载bin压缩包,然后解压 官网下载地址:https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.3.2/rocketmq-all-4.3.2- ...