Hanoi Tower Troubles Again! (找规律)
来源:互联网 发布:网络搜索优化方案 编辑:程序博客网 时间:2024/05/21 17:59
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.
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
2425
Sample Output
11337
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<set>#include<vector>#include<map>#include<cmath>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const int N = 10000;int f[111];int main(){f[1]=1;f[2]=3;int i,j,n,t;int temp=2;for(i=3;i<=50;i++) {if(i%2) temp+=2;f[i]=f[i-1]+temp;}cin>>t;while(t--) {cin>>n;cout<<f[n]<<endl;}return 0;}
0 0
- Hanoi Tower Troubles Again! (找规律)
- ZOJ1239 Hanoi Tower Troubles Again!
- zoj1239 Hanoi Tower Troubles Again!
- uva10276 hanoi tower troubles again
- Hanoi Tower Troubles Again! ZOJ
- UVa Problem 10276 Hanoi Tower Troubles Again! (汉诺塔卷土重来!)
- (挑战编程_9_8)Hanoi Tower Troubles Again!
- fjnu 1680 Hanoi Tower Troubles Again!
- zoj 1239 Hanoi Tower Troubles Again!
- UVA 10276 - Hanoi Tower Troubles Again!
- zoj 1239 Hanoi Tower Troubles Again!
- ZOJ 1239 Hanoi Tower Troubles Again!
- Uva-10276-Hanoi Tower Troubles Again!
- zoj 1239 Hanoi Tower Troubles Again!
- HDU 1329 Hanoi Tower Troubles Again!
- joj 1031 Hanoi Tower Troubles Again!解题报告
- programming-challenges Hanoi Tower Troubles Again! (110908) 题解
- Hdu1329Hanoi Tower Troubles Again!
- 最详细的Android Studio百度地图(BaiduMap)开发教程,可以用作官方文档的教程!
- 使用Python的SnowNLP模块实现情感分析
- 主成分分析法
- Atitit.code base view 视图的实现原理
- win10java环境配置
- Hanoi Tower Troubles Again! (找规律)
- LightOJ 1089 Points in Segments (II) 离散化 标记
- 263. Ugly Number
- BlueTooth: 蓝牙协议栈实现模式分析
- Struts2入门~工作原理及访问Servlet API
- Knots (组合数学)
- HDU 3078Network (LCA)
- Internet Explorer 升级到IE11遇到问题案例分析
- leetcode:字符串