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. springmvc与struts的区别

    一.拦截机制 1.Struts2 a.Struts2框架是类级别的拦截,每次请求就会创建一个Action,和Spring整合时Struts2的ActionBean注入作用域是原型模式prototype ...

  2. win7 64位mysql安装及navicat 解压版

    教程:http://jingyan.baidu.com/article/f3ad7d0ffc061a09c3345bf0.html Mysql修改设置root密码的命令及方法:http://jingy ...

  3. 九、springboot整合redis二之缓冲配置

    1.创建Cache配置类 @Configuration @EnableCaching public class RedisCacheConfig extends CachingConfigurerSu ...

  4. 说一下怎么搭建外网来访问SVN服务器

    一.搭建SVN服务器 1.所需软件 TortoiseSVN,下载地址http://tortoisesvn.net/downloads.html TortoiseSVN中文语言包,下载地址http:// ...

  5. python网络编程--线程锁(互斥锁Mutex)

    一:为什么需要线程锁 一个进程下可以启动多个线程,多个线程共享父进程的内存空间,也就意味着每个线程可以访问同一份数据,此时,如果2个线程同时要修改同一份数据,会出现什么状况? 很简单,假设你有A,B两 ...

  6. css文字环绕图片--遇到的问题及解决方法

    一.前言 需要实现一个文字环绕图片的效果,心想so easy嘛. 1)代码部分 <style> .img-left { border: 3px solid #005588; width:3 ...

  7. 简单计算器的C实现-函数指针,main函数传参

    /** 程序功能:简单计算器,实现加减乘除平方* 作者版本日期:2015.11.08 zhouhb OK* 源代码:李明 <新概念C语言培训>第33集 C语言Shell命令解释器的实现* ...

  8. mysql数据库主从同步复制原理

    MySQL的Replication(英文为复制)是一个多MySQL数据库做主从同步的方案,特点是异步复制,广泛用在各种对MySQL有更高性能.更高可靠性要求的场合.与之对应的是另一个同步技术是MySQ ...

  9. Effective STL 学习笔记 Item 17: Swap Trick

    假设有若干对象存于一个 vector 中: class Widget; vector<Widget> vw; 后来由于某些原因,从该容器中删除了若干对象(参考erase-remove id ...

  10. windows 依赖查看

    使用工具Download Process Explorer查看运行程序所依赖的动态库. 中文说明:适用于 Windows 的 Process Explorer 10.21 版