题目链接:

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

题意:

给一个上限,现在要你求一个值,这个值是用最多的小正方体拼接起来的,而且体积和尽量大;

思路:

每次贪心的选取,每次选比它小的或者改变上限选下一个;

AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1e3+20;
const double eps=1e-12; LL d[N];
pair<int,LL>ans;
int search(LL x)
{
int l=0,r=N-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(d[mid]<=x)l=mid+1;
else r=mid-1;
}
return l-1;
}
int dfs(LL cur,LL temp,int num)
{
if(num>ans.first)ans.first=num,ans.second=temp;
else if(num==ans.first&&temp>ans.second)ans.second=temp; int x=search(cur);
if(x==0)return 0;
dfs(cur-d[x],temp+d[x],num+1);
dfs(d[x]-1-d[x-1],temp+d[x-1],num+1);
} int main()
{
LL m;
ans.first=0;ans.second=0;
read(m);
for(int i=1;i<N;i++)d[i]=(LL)i*i*i;
dfs(m,0,0);
cout<<ans.first<<" "<<ans.second<<endl;
return 0;
}

  

codeforces 680D D. Bear and Tower of Cubes(dfs+贪心)的更多相关文章

  1. 【19.05%】【codeforces 680D】Bear and Tower of Cubes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

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

  3. Codeforces 680D Bear and Tower of Cubes 贪心 DFS

    链接 Codeforces 680D Bear and Tower of Cubes 题意 求一个不超过 \(m\) 的最大体积 \(X\), 每次选一个最大的 \(x\) 使得 \(x^3\) 不超 ...

  4. Codeforces 680D - Bear and Tower of Cubes

    680D - Bear and Tower of Cubes 思路:dfs+贪心,设剩余的体积为res,存在a,使得a3 ≤ res,每次取边长为a的立方体或者边长为a-1的立方体(这时体积上限变成a ...

  5. 【CodeForces】679 B. Bear and Tower of Cubes

    [题目]B. Bear and Tower of Cubes [题意]有若干积木体积为1^3,2^3,...k^3,对于一个总体积X要求每次贪心地取<=X的最大积木拼上去(每个只能取一次)最后总 ...

  6. Bear and Tower of Cubes Codeforces - 680D

    https://codeforces.com/contest/680/problem/D 一道2D,又是搞两个小时才搞出来...不过好在搞出来了 官方题解:可以证明对于m,设a是满足a^3<=m ...

  7. CodeForces 679B(Bear and Tower of Cubes)

    题意:Limak要垒一座由立方体垒成的塔.现有无穷多个不同棱长(a>=1)的立方体.要求:1.塔的体积为X(X<=m).2.在小于X的前提下,每次都选体积最大的砖块.3.在砖块数最多的前提 ...

  8. uva 10051 Tower of Cubes(DAG最长路)

    题目连接:10051 - Tower of Cubes 题目大意:有n个正方体,从序号1~n, 对应的每个立方体的6个面分别有它的颜色(用数字给出),现在想要将立方体堆成塔,并且上面的立方体的序号要小 ...

  9. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. H - Funny Car Racing

    H - Funny Car Racing Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Desc ...

  2. wcf利用IDispatchMessageInspector实现接口监控日志记录和并发限流

    一般对于提供出来的接口,虽然知道在哪些业务场景下才会被调用,但是不知道什么时候被调用.调用的频率.接口性能,当出现问题的时候也不容易重现请求:为了追踪这些内容就需要把每次接口的调用信息给完整的记录下来 ...

  3. Ubuntu 下安装JDK1.8

    好困,不行了,我要睡觉了,先上图吧!

  4. images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.

    Convolutional networks may include local or global pooling layers[clarification needed], which combi ...

  5. css3 transition效果

    <meta charset="UTF-8"> <style> .btn { display: inline-block; font-size: 12px; ...

  6. CSS 布局实例系列(二)如何通过 CSS 实现一个左边固定宽度、右边自适应的两列布局

    最近在百度 IFE 训练营中看见的一道题目: 用两种不同的方法来实现一个两列布局,其中左侧部分宽度固定.右侧部分宽度随浏览器宽度的变化而自适应变化  个人总结出如下三种实现思路: 通过绝对定位实现 S ...

  7. Linux中源码包安装

    1.准备环境 a.因为是编译安装,所以需要安装gcc编译器 b.下载源码包 2.注意事项 a.源代码保存位置 /usr/local/src/ b.软件安装位置 /usr/local/ c.如何确定安装 ...

  8. ExtASPNet web.config

    [转CSDN]:http://download.csdn.net/download/mcqq123321/4607708 修改 Web.config 打开 web.config,在 configura ...

  9. Java之线程池(二)

    关于线程和线程池的学习,我们可以从以下几个方面入手: 第一,什么是线程,线程和进程的区别是什么 第二,线程中的基本概念,线程的生命周期 第三,单线程和多线程 第四,线程池的原理解析 第五,常见的几种线 ...

  10. 第10条:尽量用enumerate取代range

    核心要点: (1)enumerate函数提供了一种精简的写法,可以在遍历迭代器时获知每个元素的索引. (2)尽量用enumerate来改写那种将range与下标访问相结合的序列遍历代码. (3)可以给 ...