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. Solr3.6.1 在Tomcat6下的环境搭建

    Solr3.6.1 在Tomcat6下的环境搭建 Tomcat路径:D:\prg\apache-tomcat-6-solr 简写为tomcat_home Solr文件下载保存路径为:F:\softwa ...

  2. 如何汉化XAF应用

    这是一个入门级的问题,应网友请求,总结一下XAF汉化过程的几个关键点. 一.所有Dev的控件的汉化,Dev官方有汉化文件.点击下载15.2版本. 正版用户登陆至官网是有专门的下载界面的,并且可以参与汉 ...

  3. 【配置属性】—Entity Framework 对应表字段的类型的设定配置方法

    摘自:http://www.cnblogs.com/nianming/archive/2012/11/07/2757997.html Entity Framework Code First的默认行为是 ...

  4. 【Java每日一题】20161213

    package Dec2016; public class Ques1213 { public static void main(String[] args){ String str1 = " ...

  5. Ubuntun CentOS的ISO官方MD5在哪里查看(安装虚拟电脑时出现严重错误的解决方法)

    近日在VirtualBox虚拟机上安装Linux,然后果断的选择了Ubuntu.当我新建虚拟机,一切配置完成之后,启动虚拟机,还没开始安装就提示虚拟电脑出现严重错误,需要关闭.起初以为是配置错了,上网 ...

  6. CSS:CSS样式表及选择器优先级总结

    我们在写网页的时候经常会遇到同一个HTML文件,使用了外部样式.内部样式以及内联样式,那么如果发生冲突时浏览器是怎么抉择的呢? 也会遇到这样的情况,在样式表中,对同一个HTML元素,我们有可能既用到了 ...

  7. Tomcat源代码-门面模式(Facade)

    从Tomcat源码提炼出设计模式-门面设计模式: 概念 外部访问内部,耦合度增加,不利于扩展.而门面模式在内部基础上进行再度封装,只提供外部想要的方法.这时访问方式由“外部---内部”变为了“外部-- ...

  8. var a=function()跟function a()的区别

    //代码一: a(); //执行这个会报错 var a = function(index){ alert(index); } a(); //执行这个不会报错 //代码二: a(); //执行这个不会报 ...

  9. jqGrid使用setColProp方法动态改变列属性

    在使用jqGrid插件时,有时我们需要动态改变列的属性,可使用setColProp方法,用法如下 jQuery(”#grid_id”).setColProp('colname',{editoption ...

  10. 解决xcode8模拟器不能删除应用的问题

       问题描述:想删除模拟器上的测试项目,但是长按之后主界面模糊一下,并没有出现小叉叉来删除.    原因:这是因为xcode8中模拟器自带Touch3D,我们控制不好触摸板的力度. 解决方法: 1. ...