zoukankan      html  css  js  c++  java
  • CF 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 volumea13 + 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 Xbetween 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 Xsecondarily 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.

     题意:当确定一个数字x后,这个数字可以用如下的方法取得,找到最大的数字l使得l^3<=x,接下来x-=l^3,这样算一步,

    再重复下去直到x==0,得到的总的步数就是数字x的权值,现在给你一个数字n求得数字1-n中权值最大的数字,并且在权值

    最大的情况下,让数字的值更大;

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <map>
    #include <algorithm>
    #include <set>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    #define MM(a,b) memset(a,b,sizeof(a));
    const double eps = 1e-10;
    const int  inf =0x7f7f7f7f;
    const double pi=acos(-1);
    int p2,q2,p1,ep,q1;
    const int INF = 0x3f3f3f3f;
    const int maxn = 1100;
    pair<int,ll> ans;
    ll p3(ll x)
    {
        return x*x*x;
    }
    void dfs(ll n,int p,ll z)
    {
        if(!n) {ans=max(ans,make_pair(p,z));return;};
        int t=1;
        while(p3(t+1)<=n) t++;
        dfs(n-p3(t),p+1,z+p3(t));
        dfs(p3(t)-p3(t-1)-1,p+1,z+p3(t-1));
    }
    
    int main()
    {
        ll n;
        while(~scanf("%lld",&n))
        {
            ans.first=ans.second=0;
            dfs(n,0,0);
            printf("%d %lld
    ",ans.first,ans.second);
        }
        return 0;
    }
    

     分析:搜索,dfs,复杂度貌似logn

  • 相关阅读:
    JS获取单选框checked的value方法
    URL链接后面的参数解析,与decode编码解码;页面刷新回到顶部jquery
    JS原生增删,判断class是否存在方法
    转载:jquery.ajax之beforeSend方法使用介绍
    css3 filter(滤镜)属性汇总与使用介绍,来源W3C
    使用 HTML5 Geolocation 构建基于地理位置的 Web 应用学习网站分享
    js获取移动端触摸坐标
    jquery如何获取手机网页触屏坐标:ontouchstart 、ontouchend、ontouchmove
    js/jquery获取浏览器窗口可视区域高度和宽度以及滚动条高度实现代码
    JS获取浏览器可视区域的尺寸
  • 原文地址:https://www.cnblogs.com/smilesundream/p/5573239.html
Copyright © 2011-2022 走看看