zoukankan      html  css  js  c++  java
  • HDU 1399 Starship Hakodate-maru(暴力搜索)

    传送门:

    http://acm.hdu.edu.cn/showproblem.php?pid=1399

    Starship Hakodate-maru

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 871    Accepted Submission(s): 587


    Problem Description
    The surveyor starship Hakodate-maru is famous for her two fuel containers with unbounded capacities. They hold the same type of atomic fuel balls.
    There, however, is an inconvenience. The shapes of the fuel containers #1 and #2 are always cubic and regular tetrahedral respectively. Both of the fuel containers should be either empty or filled according to their shapes. Otherwise, the fuel balls become extremely unstable and may explode in the fuel containers. Thus, the number of fuel balls for the container #1 should be a cubic number (n^3 for some n = 0, 1, 2, 3, ...) and that for the container #2 should be a tetrahedral number (n(n+1)(n+2)/6 for some n = 0, 1, 2, 3, ...).

    Hakodate-maru is now at the star base Goryokaku preparing for the next mission to create a precise and detailed chart of stars and interstellar matters. Both of the fuel containers are now empty. Commander Parus of Goryokaku will soon send a message to Captain Future of Hakodate-maru on how many fuel balls Goryokaku can supply. Captain Future should quickly answer to Commander Parus on how many fuel balls she requests before her ship leaves Goryokaku. Of course, Captain Future and her officers want as many fuel balls as possible.

    For example, consider the case Commander Parus offers 151200 fuel balls. If only the fuel container #1 were available (i.e. if the fuel container #2 were unavailable), at most 148877 fuel balls could be put into the fuel container since 148877 = 53 * 53 * 53 < 151200 < 54 * 54 * 54. If only the fuel container #2 were available, at most 147440 fuel balls could be put into the fuel container since 147440 = 95 * 96 * 97 / 6 < 151200 < 96 * 97 * 98 / 6. Using both of the fuel containers #1 and #2, 151200 fuel balls can be put into the fuel containers since 151200 = 39 * 39 * 39 + 81 * 82 * 83 / 6. In this case, Captain Future's answer should be "151200".

    Commander Parus's offer cannot be greater than 151200 because of the capacity of the fuel storages of Goryokaku. Captain Future and her officers know that well.

    You are a fuel engineer assigned to Hakodate-maru. Your duty today is to help Captain Future with calculating the number of fuel balls she should request.
     
    Input
    The input is a sequence of at most 1024 positive integers. Each line contains a single integer. The sequence is followed by a zero, which indicates the end of data and should not be treated as input. You may assume that none of the input integers is greater than 151200.
     
    Output
    The output is composed of lines, each containing a single integer. Each output integer should be the greatest integer that is the sum of a nonnegative cubic number and a nonnegative tetrahedral number and that is not greater than the corresponding input number. No other characters should appear in the output.
     
    Sample Input
    100 64 50 20 151200 0
     
    Sample Output
    99 64 47 20 151200
     
    Source
     
    Recommend
    Ignatius.L   |   We have carefully selected several similar problems for you:  1551 2289 2899 2199 2648 
     
     
    题目意思:
    找到满足i*i*i+j*(j+1)*(j+2)/6且小于等于n的最大值。
    水题,直接暴力
    code:
    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<queue>
    #include<set>
    #include<map>
    #include<string>
    #include<memory.h>
    using namespace std;
    int main()
    {
        int n,i,j,x;
        int ans;
        while(~scanf("%d",&n))
        {
            if(n==0)
                break;
            ans=0;
            for(i=0;i*i*i<=n;i++)
            {
                for(j=0;j*(j+1)*(j+2)/6<=n;j++)
                {
                    x=i*i*i+j*(j+1)*(j+2)/6;
                    if(x<=n)
                    {
                        ans=max(ans,x);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    springboot成神之——websocket发送和请求消息
    springboot成神之——发送邮件
    springboot成神之——spring文件下载功能
    springboot成神之——spring的文件上传
    springboot成神之——basic auth和JWT验证结合
    springboot成神之——Basic Auth应用
    leetcode-easy-array-122 best time to buy and sell stocks II
    leetcode-easy-array-31 three sum
    leetcode-mid-others-621. Task Scheduler
    leetcode-mid-math-371. Sum of Two Integers-NO-???
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9356483.html
Copyright © 2011-2022 走看看