水题,搞清楚hanoi的定义就好做了。

 /* 1329 */
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath> #define MAXN 55 int b[MAXN];
int a[MAXN]; bool isSquare(int x) {
int y = (int) sqrt(x*1.0); return y*y == x;
} void init() {
int i, j, k;
int n = ;
bool flag; memset(b, , sizeof(b));
for (i=; ; ++i) {
flag = true;
for (j=; j<n; ++j) {
if (b[j]== || isSquare(b[j]+i)) {
flag = false;
b[j] = i;
break;
}
}
if (flag) {
a[n] = i-;
b[n++] = i;
if (n > )
break;
}
}
} int main() {
int t, n; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif init();
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("%d\n", a[n]);
} return ;
}

【HDOJ】1329 Hanoi Tower Troubles Again!的更多相关文章

  1. HDU 1329 Hanoi Tower Troubles Again!(乱搞)

    Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...

  2. hdu 1329 Hanoi Tower Troubles Again!

    找规律的题目an=an-1+(i+i%2)/2*2; ;}

  3. HDU1329 Hanoi Tower Troubles Again!——S.B.S.

    Hanoi Tower Troubles Again! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. ZOJ-1239 Hanoi Tower Troubles Again!

    链接:ZOJ1239 Hanoi Tower Troubles Again! Description People stopped moving discs from peg to peg after ...

  5. 10276 - Hanoi Tower Troubles Again!(思维,模拟)

    People stopped moving discs from peg to peg after they know the number of steps needed to complete t ...

  6. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  7. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  8. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  9. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

随机推荐

  1. 赵雅智_ListView_BaseAdapter

    Android界面中有时候须要显示略微复杂的界面时,就须要我们自己定义一个adapter,而此adapter就要继承BaseAdapter,又一次当中的方法. Android中Adapter类事实上就 ...

  2. HDU--2040

    亲和数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  3. Hibernate知识点总结

    Hibernate配置二级缓存:  --- 使用EhCache 1.hibernate.cfg.xml中配置二级缓存 <hibernate-configuration>   <ses ...

  4. [AWS S3] Hosting a Static Website on Amazon S3

    In this lesson, you will learn how to host a static website on Amazon S3. I will show you how to cre ...

  5. [Javascript] Grouping and Nesting Console Log Output

    Organize your log output by grouping your logs into collapsable hierarchies using console.group(). ; ...

  6. Linux &amp; Mac curl 命令行使用——POST&amp;GET

    http提交一个表单,比較经常使用的是POST模式和GET模式 在curl的命令行下,GET模式什么option都不用.仅仅须要把变量写在url里面就能够了 比方: curl http://www.s ...

  7. 弹出层easydialog-v2.0

    地址:http://www.lanrentuku.com/down/js/qita-862/ easydialog.css ;;; } .easyDialog_wrapper{ width:320px ...

  8. java中集合类的简介

    结构 collection(接口) List(接口) LinkedList(类) ArrayList(类) Vector(类) Stack(类) Set(接口) Map(接口) Hashtable(类 ...

  9. 在eclipse中新建Dynamic web project时选择2.5和3.0的区别(里面涉及servlet和tomcat的问题)

    1.是指servlet的版本,是2.5的还是3.0的 servlet3.0以后支持异步 2.dynamic web module和对应的TOMCAT 版本 http://blog.sina.com.c ...

  10. Objective-C学习篇01—类的声明与实现

    Objective-C,是美国人布莱德·确斯(Brad Cox)于 1980 年年初发明的一 种程序设计语言,其与同时代的 C++ 一样,都是在 C 的基础上加入面向对象特性扩充而成的.Objecti ...