博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ-1399 Starship Hakodate-maru
阅读量:7069 次
发布时间:2019-06-28

本文共 3840 字,大约阅读时间需要 12 分钟。

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
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

 

转载地址:http://iohll.baihongyu.com/

你可能感兴趣的文章
会话标识未更新
查看>>
XCode使用技巧
查看>>
剑指offer数组2
查看>>
python基础之生成器迭代器
查看>>
python系统编程(二)
查看>>
洛谷P2894 [USACO08FEB]酒店Hotel
查看>>
bzoj千题计划159:bzoj2055: 80人环游世界(有源汇上下界可行最小费用流)
查看>>
pyhton3解决"tuple parameter unpacking is not supported"问题
查看>>
安装vmware vCenter Appliance
查看>>
PHP函数
查看>>
ORACLE 更新关联多张表
查看>>
弹性盒子布局
查看>>
SQL中的case when then else end用法
查看>>
【字王的野望】
查看>>
NOIP2015提高组T2 洛谷P2661 信息传递
查看>>
POJ1692 Crossed Matchings
查看>>
linux基础命令二
查看>>
机器学习&数据挖掘笔记_22(PGM练习六:制定决策)
查看>>
网络编程路线
查看>>
Mysql主从备份和SQL语句的备份
查看>>