Hanoi Tower Troubles Again! (找规律)
2016-02-27 19:33
1431 查看
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
Sample Output
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
#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 <<endl; } return 0; }
相关文章推荐
- GetPostBackEventReference加RaisePostBackEvent实现自定义控件中回调传参
- Codeforces - AIM Tech Round (Div. 2)C - Graph and String
- ZOJ 3780 Paint the Grid Again
- 使用Keychain配置
- Leet Code OJ 70. Climbing Stairs [Difficulty: Easy]
- 1021 Fibonacci Again
- 集训队专题(7)1001 Drainage Ditches
- train validation test
- 1090 Higest Price in Supply Chain
- 102.Daikon Forge基础使用label、button、sprite、textureAtlas、font
- UVA 10976(p183)----Fractions Again?!
- VS2012 error C2664: “std::make_pair”:无法将左值绑定到右值引用
- 101.Daikon Forge插件介绍和安装
- 格式化数据#8: AIE实验室交流群推荐的相关书籍(附豆瓣链接和ISBN)
- hdu 1151 Air Raid
- DNS IP DOMAIN 详解
- 解决dubbox-demo-provider.xml报错的问题:提示Failed to read schema document
- 【leetcode】【11】Container With Most Water
- 如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]
- leetcode 11.Container With Most Water