zoukankan      html  css  js  c++  java
  • Codeforces 680D

    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
    Copy
    48
    output
    Copy
    9 42
    input
    Copy
    6
    output
    Copy
    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.

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #define maxn 100010
    using namespace std;
    long long a[maxn];
    pair<long long ,long long>ans;
    void dfs(long long now,long long cnt,long long sum){
        if(now==0){
            ans=max(ans,make_pair(cnt,sum));
            return;
        }
        int pos=upper_bound(a+1,a+100001+1,now)-a;
        --pos;
        dfs(now-a[pos],cnt+1,sum+a[pos]);
        if(pos>1)
            dfs(a[pos]-a[pos-1]-1,cnt+1,sum+a[pos-1]);
    }
    int main(){
        long long p;
        scanf("%lld",&p);
        for(long long i=1;i<=100001;i++)
            a[i]=i*i*i;
        dfs(p,0,0);
        printf("%lld %lld
    ",ans.first,ans.second);
        return 0;
    }
  • 相关阅读:
    .net项目的svn Global ignore pattern
    Ionic开发中常见问题和解决方案记录
    iOS开发:mac使用svn管理项目
    iOS开发:本地数据存储-NSUserDefaults
    iOS开发:插件记录
    iOS开发:告诉git不要跟踪UserInterfaceState.xcuserstate
    发布 windows 10 universal app 时微软账号验证失败
    iOS开发:UINavigationController常用操作
    iOS开发:Swift多线程NSOperation的使用
    iOS开发:Swift多线程GCD的使用
  • 原文地址:https://www.cnblogs.com/thmyl/p/12250238.html
Copyright © 2011-2022 走看看