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 ...
随机推荐
- Office DDE漏洞学习笔记
1.前言 2017年下半年爆发出来的Office漏洞,一直没有空做笔记记录.在病毒分析中也看到有利用这个漏洞的样本,针对Office系列软件发起的钓鱼攻击和APT攻击一直是安全攻防的热点. 2.off ...
- layui table表格字段过长,展示不完整时,鼠标放到上面展示完整信息
亲测可以直接用 1.首先每个列都有一个title,里面放入完整信息,然后写一个如下的function, function tdTitle(){ $('th').each(function(index, ...
- python内置模块之itertools
前言 itertools模块是python内置的迭代器模块,定义了可生成多种迭代器的函数,用来代替可迭代对象的遍历等操作,节约内存. 迭代器函数的类型 无限迭代器:包括count.cycle.repe ...
- 聊天室(上篇)GatewayWorker 基础
前言 本文的目的是基于 GatewayWorker 官方手册,梳理一次 GatewayWorker,并在实践中与 MVC 框架整合的思路(附最终的项目源码).如果你已经理解了整合这一块儿的知识,那么就 ...
- SQL行列转换的另一种方法
create table tb(姓名 varchar(10) , 课程 varchar(10) , 分数 int)insert into tb values('张三' , '语文' , 74)inse ...
- Ubuntu 搭建ELK
一.简介 官网地址:https://www.elastic.co/cn/ 官网权威指南:https://www.elastic.co/guide/cn/elasticsearch/guide/curr ...
- Effective STL 学习笔记: Item 22 ~ 24
Effective STL 学习笔记: Item 22 ~ 24 */--> div.org-src-container { font-size: 85%; font-family: monos ...
- [C++]返回最值元素
1 priority_queue C++中优先队列是一种特殊的队列,能够返回队列中优先级最大或者最小的元素,其内部是由堆实现的,个人认为这种方式使用更加直观. 1.1 返回vector中的最值元素 # ...
- U盘删除文件时提示“文件或目录损坏且无法读取”的解决方法
U盘删除文件时提示“文件或目录损坏且无法读取”的解决方法 出现原因:在写入或读取文件时,进行复制操作,此时复制到的文件是不完整的!或者移动硬盘/U盘中途被拔出,导致文件损坏 异常现象:被删文件(夹)属 ...
- VMware虚拟机的三种联网方法及原理(转)
转自:http://blog.chinaunix.net/uid-24876683-id-3593774.html 一.Brigde——桥接 :默认使用VMnet0 .原理: Bridge 桥&quo ...