HDU1329 Hanoi Tower Troubles Again!——S.B.S.
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
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.
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.
an integer indicating the maximal number of balls that can be placed. Print -1
if an infinite number of balls can be placed.
4
25
337
#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.的更多相关文章
- ZOJ-1239 Hanoi Tower Troubles Again!
链接:ZOJ1239 Hanoi Tower Troubles Again! Description People stopped moving discs from peg to peg after ...
- HDU 1329 Hanoi Tower Troubles Again!(乱搞)
Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...
- 10276 - Hanoi Tower Troubles Again!(思维,模拟)
People stopped moving discs from peg to peg after they know the number of steps needed to complete t ...
- 【HDOJ】1329 Hanoi Tower Troubles Again!
水题,搞清楚hanoi的定义就好做了. /* 1329 */ #include <cstdio> #include <cstring> #include <cstdlib ...
- hdu 1329 Hanoi Tower Troubles Again!
找规律的题目an=an-1+(i+i%2)/2*2; ;}
- Codeforces Gym 100114 A. Hanoi tower 找规律
A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...
- 汉诺塔 Hanoi Tower
电影<猩球崛起>刚开始的时候,年轻的Caesar在玩一种很有意思的游戏,就是汉诺塔...... 汉诺塔源自一个古老的印度传说:在世界的中心贝拿勒斯的圣庙里,一块黄铜板上插着三支宝石针.印度 ...
- 3-6-汉诺塔(Hanoi Tower)问题-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版
课本源码部分 第3章 栈和队列 - 汉诺塔(Hanoi Tower)问题 ——<数据结构>-严蔚敏.吴伟民版 源码使用说明 链接☛☛☛ <数据结构-C语言版> ...
- 1028. Hanoi Tower Sequence
1028. Hanoi Tower Sequence Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Hanoi Tow ...
随机推荐
- 【转】窗口之间的主从关系与Z-Order
原文链接:http://www.cnblogs.com/dhatbj/p/3288152.html 说明:这是本人2008年写的一篇旧文,从未公开发表过.其中除了一小段描述Window Mobile平 ...
- 从头开始搭建一个dubbo+zookeeper平台
本篇主要是来分享从头开始搭建一个dubbo+zookeeper平台的过程,其中会简要介绍下dubbo服务的作用. 首先,看下一般网站架构随着业务的发展,逻辑越来越复杂,数据量越来越大,交互越来越多之后 ...
- Spring(一)
一. spring是什么? 我们知道struts 是 web 框架 (jsp/action/actionfrom).hibernate 是 orm框架,处于持久层. spring 是容器框架,用于配置 ...
- (原)3.4 Zookeeper应用 - 分布式锁
本文为原创文章,转载请注明出处,谢谢 分布式锁 1.原理 建立表示锁的父节点(图中locker节点) 每个争抢锁的服务器在locker节点下创建有序的临时节点 判断自己是否抢到锁:获取locker下所 ...
- HTML5学习之 开发工具
Notepad++.Editplus 是常用的开发编辑器.这些在Window系统下,比较容易找到,但是在MAC系统下,有的是收费的,有的是不支持.我开发的时候,用的是TextWrangler,如图: ...
- iOS PresentViewControlle后,直接返回根视图
在开发中:用[self presentViewController:VC animated:YES completion:nil];实现跳转,多次跳转后,直接返回第一个. 例如: A presentV ...
- app上架流程的整理
app的上架流程 一.准备工作 首先需要有开发者账号,企业级的账号是299$,个人开发者账号是99$,没有的话可以登录http://developer.apple.com/自行申请 假如你已经有账号了 ...
- [Android]一个干净的架构(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5276587.html 一个干净的架构 原文:https://b ...
- Android 手机卫士--是否有密码区分对话框类型
本文开始逐步实现设置中心的“手机防盗”功能模块 本文地址:/www.cnblogs.com/wuyudong/p/5939123.html,转载请注明出处. 点击“手机防盗”,如果之前没有设置过密码, ...
- 【代码笔记】iOS-图片手势,上传照片
代码: RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIViewControl ...