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. 【手记】未能从程序集System.Net.Http.Formatting中加载类型System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter

    实际报错如图: 如果你跟我一样是在折腾Asp.Net WebApi 2.x时遇到这个问题,请参看如下办法: 删除现有System.Net.Http.Formatting引用(如果引用了的话) 重新引用 ...

  2. jquery css事件编程 尺寸设置

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Apache Lucene学习笔记

    Hadoop概述 Apache lucene: 全球第一个开源的全文检索引擎工具包 完整的查询引擎和搜索引擎 部分文本分析引擎 开发人员在此基础建立完整的全文检索引擎 以下为转载:http://www ...

  4. eclipse里打开SWT项目找不到source/design的图形UI设计界面

    因为前天重新装了个新版的eclipse, 结果今天打开一个SWT的项目,突然找不到source/design的图形UI设计的两个切换按钮 我把SWT组件重新装了还是找不到.结果后来发现是因为重装ecl ...

  5. Lind.DDD.Paging分页模块介绍

    回到目录 分页组件网上有很多,MVC.Pager,JSPager等,通过实现方式大体分为前端分页和后端分页,前端分页是前台对list内存本地集合进行分页,缺点就是在大数据情况下,内存占用过高:后端分页 ...

  6. [连载]《C#通讯(串口和网络)框架的设计与实现》-2.框架的总体设计

    目       录 C#通讯(串口和网络)框架的设计与实现... 1 (SuperIO)- 框架的总体设计... 1 第二章           框架总体的设计... 2 2.1           ...

  7. 三道简单的前端HTML/CSS题目

    使用CSS为多个网页进行相同风格的布局和外观设置时,为了方便对这些网页进行修改,最好使用( ).http://hovertree.com/shortanswer/bjae/7bd72acca32068 ...

  8. $.extend()的深拷贝和浅拷贝详细讲解

    版权声明:作者原创,转载请注明出处! 语法:jQuery.extend( [deep ], target, object1 [, objectN ] ) 描述: 将两个或更多对象的内容合并到第一个对象 ...

  9. HotApp小程序统计之自定义事件统计

    什么是自定义事件统计     官网:https://weixin.hotapp.cn/document 自定事件,就是自定统计任意事件的执行,灵活度最高. 用上图的云笔记说明想知道如下信息 (1)多少 ...

  10. entity Framework codefirst Migrations

    一次数据迁移的记录 首先在vs工具里面使用打开程序包管理器控制台 在控制台上面选择程序集为数据访问层 注意配置生成app里面的连接字符串 在控制台输入 Enable-Migrations 会自动生成一 ...