HDU 1399 水的嘛就不谈了

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<vector>
#define ENTER printf("\n");
//快速打印一个数组
#define ll long long
#define NUM 100
#define MOD 1000
using namespace std;
//构造函数 析构函数怎么打印出地址
int cubic[53 + 1];
int tet[95 + 1];
int n;
//在cubic中二分查找最大的那个小于x的数
int binary_search(int cubic[], int x)
{
	int left = 1;
	int right = 53;
	int mid;
	while (left + 1 < right)
	{
		mid = (left + right) >> 1;
		if (cubic[mid] == x)
		{
			return x;
		}
		else if (cubic[mid] < x)
		{
			left = mid;
		}
		else
		{
			right = mid;
		}
	}
	return cubic[left];
}
int binary_search1(int tet[], int x)
{
	int left = 1;
	int right = 95;
	int mid;
	while (left + 1 < right)
	{
		mid = (left + right) >> 1;
		if (tet[mid] == x)
		{
			return x;
		}
		else if (tet[mid] < x)
		{
			left = mid;
		}
		else
		{
			right = mid;
		}
	}
	return tet[left];
}
int main()
{
	for (int i = 1; i <= 53; i++)
	{
		cubic[i] = i * i * i;
	}
	for (int i = 1; i <= 95; i++)
	{
		tet[i] = i * (i + 1) * (i + 2) / 6;
	}
	while (scanf("%d", &n) != EOF && n)
	{
		int a1 = binary_search1(cubic, n);
		int a2 = binary_search1(tet, n);
		int a3 = 0x80000000;
		for (int i = 1; i <= 53; i++)
		{
			for (int j = 1; j <= 95; j++)
			{
				if (cubic[i] + tet[j] > n)
					break;
				a3 = max(cubic[i] + tet[j], a3);
			}
		}
		printf("%d\n", max(a1, max(a2, a3)));
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值