当前位置: 代码迷 >> 综合 >> poj 1406 Starship Hakodate-maru 暴力枚举
  详细解决方案

poj 1406 Starship Hakodate-maru 暴力枚举

热度:6   发布时间:2024-01-19 05:54:55.0

水题,直接贴代码。

//poj 1406
//sep9
# include<iostream>
using namespace std;
__int64 f1[2024];
__int64 f2[3024];
int main()
{__int64 index1=0,index2=0,n;for(index1=0;index1<1300;++index1)f1[index1]=index1*index1*index1;for(index2=0;index2<2350;++index2)f2[index2]=index2*(index2+1)*(index2+2)/6;	while(scanf("%I64d",&n)&&n){__int64 maxx=0;		__int64 i,j;for(i=0;i<index1&&f1[i]<=n;++i)for(j=0;j<index2;++j)if(f1[i]+f2[j]<=n)maxx=max(maxx,f1[i]+f2[j]);else break;printf("%I64d\n",maxx);}return 0;	
}