hdu 1399 Starship Hakodate-maru (暴力搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1399
题目大意:找到满足i*i*i+j*(j+1)*(j+2)/6形式且小于等于n的最大值。
#include<iostream>
#include<cstdio> using namespace std; int main()
{
int n;
while(scanf("%d",&n),n)
{
int j,k,max=;
for(j=; j*(j+)*(j+)/<=n; j++)
{
for(k=; k*k*k<=n; k++)
{
if(k*k*k+j*(j+)*(j+)/>n)
break;
}
if(max<(k-)*(k-)*(k-)+j*(j+)*(j+)/&&(k-)*(k-)*(k-)+j*(j+)*(j+)/<=n)
max=(k-)*(k-)*(k-)+j*(j+)*(j+)/;
}
printf("%d\n",max);
}
}
还有第二种认为不错的代码。
#include <iostream>
#include <cstdio>
#include <cmath> using namespace std; int main()
{
int n,t,max,res;
while(scanf("%d",&n)!=EOF)
{
if(n==) break;
max=;
for(int i=; i*(i+)*(i+)/<=n; i++)
{
res=;
t=n-i*(i+)*(i+)/;
for(int j=(int)pow(n,1.0/); j>=; j--)
{
if(j*j*j<=t)
{
res=j*j*j;
break;
}
}
if(res+i*(i+)*(i+)/>max)
max=res+i*(i+)*(i+)/;
}
printf("%d\n",max);
}
return ;
}
hdu 1399 Starship Hakodate-maru (暴力搜索)的更多相关文章
- HDU 1399 Starship Hakodate-maru(暴力搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1399 Starship Hakodate-maru Time Limit: 2000/1000 MS ...
- HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)
主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...
- hdu 4740 The Donkey of Gui Zhou(暴力搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740 [题意]: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次 ...
- HDU 3131 One…Two…Five! (暴力搜索)
题目链接:pid=3131">HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6= ...
- hdu 1427 速算24点 dfs暴力搜索
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem De ...
- ACM 暴力搜索题 题目整理
UVa 129 Krypton Factor 注意输出格式,比较坑爹. 每次要进行处理去掉容易的串,统计困难串的个数. #include<iostream> #include<vec ...
- HDU 1312 Red and Black --- 入门搜索 BFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- HDU 1312 Red and Black --- 入门搜索 DFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- 随手练——洛谷-P1151(枚举与暴力搜索)
枚举 #include <iostream> using namespace std; int main() { ; cin >> k; ; i < ; i++) { ) ...
随机推荐
- spring boot 连接mysql 错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one
1.spring boot 整合mybatis 连接mysql时错误 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or repr ...
- iframe底边多出4px或5px解决办法
问题: 在处理iframe框架自适应时,并且已经去掉iframe的边框,但仍然出现底边多出4px或5px高度的情况.如图 <div id="content"> < ...
- 【page.json】配置说明
页面.json用来对本页面的窗口表现进行配置.它只能针对window配置,并且会覆盖 app.json 的 window 中相同的配置项. { /** * 以下是页面顶部导航栏设置 **/ " ...
- mysql 数据库 exists 和count
由于最近在使用exists是出现了一个小问题,但是在调试的时候费了不少时间,因为自己只是牢固造成,所以在在此记录,已提醒自己. mysql中exists 用法: 通过和主查询管理 以达到过滤的效果,如 ...
- php中数据类型的强制转换
1.在PHP开发种在很多的地方要涉及到数据类型的转换,尤其是涉及到金额的数据类型,一定要转换成float类型,否则在入库的时候可能会因为数据类型的不同覆盖掉之前的金额.(字符串和float类型相加) ...
- Spring 学习笔记(八)—— 注解使用整合
@Autowired —— 自动装配 需先在配置文件中,配置一个org.springframework.beans.factory.annotation. AutowiredAnnotationBe ...
- 【SSH】——梳理三大框架
[前言] 去年软考,从System.out.println("Hello World!")开始,小编也算是进入java的世界了.转战java以后,虽然仍旧在学习.NET的知识,但越 ...
- vue2.0实现页面刷新时某个input获得focus
通过自定义指令:
- 【转】Word单引号‘’替换为正确的单引号(plsql参数的单引号)
转自 http://jingyan.baidu.com/article/39810a23db44b5b636fda6f2.html 问题描述: 单引号明显不一样,替换不了 解决方案,如下图
- SPOJ HIGH(生成树计数,高斯消元求行列式)
HIGH - Highways no tags In some countries building highways takes a lot of time... Maybe that's bec ...