Hanoi Tower Troubles Again!

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

Problem Description
People stopped moving discs from peg to peg after they
know the number of steps needed to complete the entire task. But on the other
hand, they didn't not stopped thinking about similar puzzles with the Hanoi
Tower. Mr.S invented a little game on it. The game consists of N pegs and a LOT
of balls. The balls are numbered 1,2,3... The balls look ordinary, but they are
actually magic. If the sum of the numbers on two balls is NOT a square number,
they will push each other with a great force when they're too closed, so they
can NEVER be put together touching each other.

The player should place one ball
on the top of a peg at a time. He should first try ball 1, then ball 2, then
ball 3... If he fails to do so, the game ends. Help the player to place as many
balls as possible. You may take a look at the picture above, since it shows us a
best result for 4 pegs.

 
Input
The first line of the input contains a single integer
T, indicating the number of test cases. (1<=T<=50) Each test case contains
a single integer N(1<=N<=50), indicating the number of pegs available.
 
Output
For each test case in the input print a line containing
an integer indicating the maximal number of balls that can be placed. Print -1
if an infinite number of balls can be placed.
 
Sample Input
2
4
25
 
Sample Output
11
337
 
Source
 
Recommend
Ignatius.L   |   We have carefully selected several
similar problems for you:  1308 1313 1317 1330 1297 
————————————————我是分割线————————————————————————————————
一道水题。
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
int t,n,i,f[];
f[]=;f[]=;
for(i=;i<=;i++)
{
if(i%)
f[i]=f[i-]+i+;//当最小路径覆盖为奇数时,就=f[i-1]+i+1;
else
f[i]=f[i-]+i;//否则就是上一个数+i;
}
cin>>t;
while(t--)
{
cin>>n;
cout<<f[n]<<endl;
}
return ;
}

HDU1329 Hanoi Tower Troubles Again!——S.B.S.的更多相关文章

  1. ZOJ-1239 Hanoi Tower Troubles Again!

    链接:ZOJ1239 Hanoi Tower Troubles Again! Description People stopped moving discs from peg to peg after ...

  2. HDU 1329 Hanoi Tower Troubles Again!(乱搞)

    Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...

  3. 10276 - Hanoi Tower Troubles Again!(思维,模拟)

    People stopped moving discs from peg to peg after they know the number of steps needed to complete t ...

  4. 【HDOJ】1329 Hanoi Tower Troubles Again!

    水题,搞清楚hanoi的定义就好做了. /* 1329 */ #include <cstdio> #include <cstring> #include <cstdlib ...

  5. hdu 1329 Hanoi Tower Troubles Again!

    找规律的题目an=an-1+(i+i%2)/2*2; ;}

  6. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  7. 汉诺塔 Hanoi Tower

    电影<猩球崛起>刚开始的时候,年轻的Caesar在玩一种很有意思的游戏,就是汉诺塔...... 汉诺塔源自一个古老的印度传说:在世界的中心贝拿勒斯的圣庙里,一块黄铜板上插着三支宝石针.印度 ...

  8. 3-6-汉诺塔(Hanoi Tower)问题-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第3章  栈和队列 - 汉诺塔(Hanoi Tower)问题 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ <数据结构-C语言版> ...

  9. 1028. Hanoi Tower Sequence

    1028. Hanoi Tower Sequence Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Hanoi Tow ...

随机推荐

  1. SharePoint 列表的导出导入

    有一群友问到关于 SharePoint 列表的导入与导出的问题,而最近也要做相关操作且好久没写博客了,所以记录下来,过程其实相当简单. 方法:将 列表 保存为 模板(可包含数据),下载模板文件,上传到 ...

  2. Unity3D 5.x 简单实例 - 发射炮弹

    1,下载.安装: http://unity3d.com/cn/get-unity/download/archive 建议直接借助 UnityDownloadAssistant 进行安装,根据需要勾选需 ...

  3. Jenkins在Windows系统dotnet平台持续集成

            之前写过一篇文章是在CentOS上构建.net自动化编译环境, 今天这篇是针对于Windows平台的环境.        Jenkins是一个开源软件项目,旨在提供一个开放易用的软件平 ...

  4. Lind.DDD.UoW工作单元的实现

    回到目录 工作单元UoW我们几乎在任务一个像样的框架里都可以找到它的足迹,是的,对于大型系统来说,他是很重要的,保持数据一致性,维持事务状态这都是它要为系统实现的功能,而在不同的框架里,实现UoW的机 ...

  5. kafkaspot在ack机制下如何保证内存不溢

    新浪微博:intsmaze刘洋洋哥.   storm框架中的kafkaspout类实现的是BaseRichSpout,它里面已经重写了fail和ack方法,所以我们的bolt必须实现ack机制,就可以 ...

  6. python字符串连接的N种方式

    python中有很多字符串连接方式,今天在写代码,顺便总结一下: 最原始的字符串连接方式:str1 + str2 python 新字符串连接语法:str1, str2 奇怪的字符串方式:str1 st ...

  7. line-height行高与图片的隐匿文本间隙消除方法

    (标注 文章来源 http://www.zhangxinxu.com/wordpress/2015/08/css-deep-understand-vertical-align-and-line-hei ...

  8. 深入理解和应用display属性(二)

    四.inline-block 此类元素是inline + block的合体 1) margin和padding都有效:width和height都有效: .inline{ display: inline ...

  9. CSS中越界问题经典解决方案

    8.CSS相关知识 (1)如何解决父元素的第一个子元素的margin-top越界问题 1)为父元素加border-top: 1px;——有副作用 2)为父元素指定padding-top: 1px;—— ...

  10. Git常用命令总结

    Git常用命令总结 git init      在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹.   git clone ...