您的位置:首页 > 其它

Codeforces Round #356 D.Bear and Tower of Cubes DFS

2016-06-10 22:16 459 查看
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


题意:有一个体积为m的塔,要你尽可能找最大的p使得p^3<=M,最后使得该塔尽可能地被填满在总体积在不大于m的条件下尽可能最大,其次从而使得用的立方体数目最多。

思路:dfs分别去考虑当前最大的p是否用上了,用上了则当前体积为m-p^3,反之体积变为p^3-1,这样才使得p不会被用上。

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<bitset>
#include<utility>
#include<functional>
#include<iomanip>
#include<sstream>
#include<ctime>
using namespace std;

#define maxn int(1e3+20)
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define PI acos(-1.0)
typedef long long ll;
typedef pair<ll ,ll> point;
ll get_max(ll n)
{
ll L = 1,R = ll(1e5+10),mid,ans = 1;
while(L <= R)
{
mid = (R + L)/2LL;
if(mid*mid*mid <= n){
L = mid+1;
ans = mid;
}
else{
R = mid-1;
}
}
return ans;
}
ll get_pow(ll p)
{
return p*p*p;
}
point ans;
void solve(ll m,ll sum,ll num)
{
if(m == 0){
ans = max(ans,make_pair(num,sum));
return;
}
ll ma = get_max(m);
solve(m - get_pow(ma),sum+get_pow(ma),num+1);
if(ma-1 >= 0){
solve(get_pow(ma) - get_pow(ma-1) -1,sum+get_pow(ma-1),num+1);
}
}
int main()
{
#ifdef CDZSC_June
freopen("t.txt", "r", stdin);
#endif
ll a;
while(~scanf("%lld",&a))
{
ans = make_pair(0,0);
solve(a,0,0);
printf("%lld %lld\n",ans.first,ans.second);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: