zoj1239 Hanoi Tower Troubles Again!
来源:互联网 发布:linux下创建用户组 编辑:程序博客网 时间:2024/05/21 17:47
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
给出n个柱子,从第一个柱子开始放珠子,珠子编号从1开始,要求每个柱子上相邻两个珠子的和是可开方的。
#include<stdio.h>#include<math.h>#include<string.h>int a[55];int main(){ int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); int n; scanf("%d",&n); int poit=1; int s=1; while(1) { if(poit>n) break; if(a[poit]==0) { a[poit]=s; s++; poit=1; continue; } else { int b=a[poit]+s; int c=sqrt(b); if(c*c==b) { a[poit]=s; s++; poit=1; continue; } } poit++; } printf("%d\n",s-1); } return 0;}
- ZOJ1239 Hanoi Tower Troubles Again!
- zoj1239 Hanoi Tower Troubles Again!
- UVa10276 HDU1329 ZOJ1239 Hanoi Tower Troubles Again!【递推函数+打表】
- uva10276 hanoi tower troubles again
- Hanoi Tower Troubles Again! ZOJ
- 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!
- Hanoi Tower Troubles Again! (找规律)
- joj 1031 Hanoi Tower Troubles Again!解题报告
- UVa Problem 10276 Hanoi Tower Troubles Again! (汉诺塔卷土重来!)
- (挑战编程_9_8)Hanoi Tower Troubles Again!
- programming-challenges Hanoi Tower Troubles Again! (110908) 题解
- 基于LDAP的opends说明与安装
- linux下redmine安装笔记
- makefile include
- <zz>libsvm / liblinear中的交叉训练技巧
- Android中的信号强度上报与显示完整流程
- zoj1239 Hanoi Tower Troubles Again!
- Linux 进程管理
- resource is out of sync with the file system解决方法
- C#读写文件
- usb传输方式
- C#一个完整的电子邮件操作类
- 大学生的幸福--天空16度蓝
- mysql 双机热备实战
- java数组与容器之间的转换,实现数组扩容