zoukankan      html  css  js  c++  java
  • HDOJ1399 Starship Hakodatemaru

    Starship Hakodate-maru

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


    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
     
     1 /* 功能Function Description:     HDOJ-1399
     2    开发环境Environment:          DEV C++ 4.9.9.1
     3    技术特点Technique:
     4    版本Version:
     5    作者Author:                   可笑痴狂
     6    日期Date:                      20120820
     7    备注Notes:
     8    题意:
     9         给你一个数n,判断在n之下,最大能够表示为k^3+m*(m+1)*(m+2)/6形式的数
    10         (易得x^3=x*(x+1)*(x+2)/6 的解为0,1,2,当n>2时,x^3<x*(x+1)*(x+2)/6.....后来想想这里不用分析)
    11     思路:
    12         枚举m,然后验证k是不是一个三次方的数
    13         事先预处理一个数组,里面存上i^3,这样以后在查询的时候效率就大大提高
    14 */
    15 #include<stdio.h>
    16 
    17 int cubic[54];
    18 
    19 void init()
    20 {
    21     int i,j;
    22     for(i=0,j=0;i<54;++i)
    23         cubic[j++]=i*i*i;
    24 }
    25 
    26 int main()
    27 {
    28     int i,j,ans,sum;
    29     init();
    30     while(scanf("%d",&sum),sum)
    31     {
    32         ans=0;
    33         for(i=0;i*(i+1)*(i+2)/6<=sum;++i)
    34         {
    35             for(j=53;j>=0;--j)
    36             {
    37                 if(cubic[j]<=sum-i*(i+1)*(i+2)/6)
    38                     break;
    39             }
    40             if(ans<i*(i+1)*(i+2)/6+cubic[j])
    41                 ans=i*(i+1)*(i+2)/6+cubic[j];
    42         }
    43         printf("%d\n",ans);
    44     }
    45     return 0;
    46 }
    功不成,身已退
  • 相关阅读:
    使用SilverLight构建插件式应用程序(九) —聊天插件客户端的实现
    .NET 访问JAVA的WebService使用SOAP头
    使用SilverLight构建插件式应用程序(七)
    管理类软件的界面模板。
    使用SilverLight构建插件式应用程序(六)
    使用SilverLight开发ARPG游戏(一)
    AS 学习笔记 元件和代码的绑定
    scaleform 学习笔记1
    cocos2dx 获取图片的某像素点的RGBA颜色
    接触的第二个引擎 scaleform
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2647246.html
Copyright © 2011-2022 走看看