Codeforces 680D Bear and Tower of Cubesp【贪心+Dfs】有点难度啊T T

186 篇文章 0 订阅

D. Bear and Tower of Cubes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
48
Output
9 42
Input
6
Output
6 6
Note

In the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.

In more detail, after choosing X = 42 the process of building a tower is:

  • Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15.
  • The second added block has side 2, so the remaining volume is 15 - 8 = 7.
  • Finally, Limak adds 7 blocks with side 1, one by one.

So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42.


题目大意:

给你一个数m,让你找【1,m】的一个数X.使得X按照规则操作次数最多,问这个X是谁,最多有多少次操作。

操作规则:

对于一个数num,每次操作找到一个数a,使得a^3<=num&&(a+1)^3>num;


思路:


1、我们考虑模拟过程,对于数字m来讲,本次操作找到了数字a.那么其实我们可以考虑减小这个a,来使得m减小的同时,能够增大操作次数(因为很明显,1可以使用0~7个,2可以使用0~3个,3可以使用0~2个,a>=4的只能使用1个)。

那么我们可以考虑对于数字m来讲,

①选择a去减小,那么此时减小结果为m-a^3;

②选择a-1去减小,那么此时一定要先减小m才行,很显然,m一定要减小到a^3-1是最贪心的。那么此时减小完的结果为:a^3-1-(a-1)^3;

③如果选择a-2去减小,很显然m一下子就要变得很小,考虑到中间减小的这一大部分值可能会有更多的变数,那么我们不去选择a-2以后的情况。


2、那么过程中就有两种选择,要么用a去减小,要么用a-1去减小,对于数字n来讲,都选择a去减小的操作数也不会很大,所以这里可以Dfs暴力选择。

过程维护一下最大值即可。


Ac代码:

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
ll ans1,ans2;
void Dfs(ll num,ll level,ll limit)
{
    if(num<0)return ;
    if(num==0)
    {
        if(level>ans1)
        {
            ans1=level;
            ans2=limit;
        }
        return ;
    }
    ll x=1;
    while((x+1)*(x+1)*(x+1)<=num)x++;
    Dfs(num-x*x*x,level+1,limit+x*x*x);
    if(x>1)Dfs(x*x*x-1-(x-1)*(x-1)*(x-1),level+1,limit+(x-1)*(x-1)*(x-1));
}
int main()
{
    ll n;
    while(~scanf("%I64d",&n))
    {
        ans1=0;
        Dfs(n,0,0);
        printf("%I64d %I64d\n",ans1,ans2);
    }
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值