12 2014 档案

摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053#include#includeint main(){ int n,k; while(~scanf("%d",&n)){ k=sqrt(n); if(k*k=... 阅读全文
posted @ 2014-12-30 11:50 zmiao 阅读(197) 评论(0) 推荐(0) 编辑
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1563当然比较直接的想法使用一个哈希表。但更好的方法是用异或!!#includeint main(){ int n,m,s; while(scanf("%d",&n),n) { s=... 阅读全文
posted @ 2014-12-29 07:59 zmiao 阅读(179) 评论(0) 推荐(0) 编辑
摘要:当n个编号元素放在n个编号位置,元素编号与位置编号各不对应的方法数用D(n)表示,那么D(n-1)就表示n-1个编号元素放在n-1个编号位置,各不对应的方法数,其它类推.第一步,把第n个元素放在一个位置,比如位置k,一共有n-1种方法;第二步,放编号为k的元素,这时有两种情况:⑴把它放到位置n,那么... 阅读全文
posted @ 2014-12-29 05:06 zmiao 阅读(189) 评论(0) 推荐(0) 编辑
摘要:每一个递归问题都可以改成DP来做。。。只不过DP会浪费一些空间罢了。。DP只是把之前的结果存起来以防再算一遍罢了。。。。。 阅读全文
posted @ 2014-12-26 09:56 zmiao 阅读(395) 评论(0) 推荐(0) 编辑
摘要:This is my favourite way to iterate through a string. You can do what you want per word.string line = "a line of text to iterate through";string word;... 阅读全文
posted @ 2014-12-26 04:38 zmiao 阅读(123) 评论(0) 推荐(0) 编辑
摘要:include #include using namespace std;void swap(char &c1, char &c2){ char tmp = c1; c1= c2; c2= tmp;}void perm(string s, int i, int n){ if(... 阅读全文
posted @ 2014-12-25 13:13 zmiao 阅读(124) 评论(0) 推荐(0) 编辑
摘要:题目:HDOJ 2561#include #include #include #include #include #include #include #include #include #include using namespace std;//const double E = 2.7182818... 阅读全文
posted @ 2014-12-25 06:39 zmiao 阅读(325) 评论(0) 推荐(0) 编辑
摘要:Runtime: O(n) — Moore voting algorithm: We maintain a current candidate and a counter initialized to 0. As we iterate the array, we look at the curren... 阅读全文
posted @ 2014-12-24 12:50 zmiao 阅读(151) 评论(0) 推荐(0) 编辑
摘要:有些HDOJ上的题目明明已经到O(n)算法了,比如1029题,时间复杂度已经最优了,但还是会TLE。主要原因是java的IO不够快。比如input是这样格式的:51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1读每一组数据的时候,最好不要用sc.nextI... 阅读全文
posted @ 2014-12-23 04:21 zmiao 阅读(116) 评论(0) 推荐(0) 编辑
摘要:最小公倍数least common multiple (LCM).最大公约数greatest common divisor (GCD).代码如下: public static int lcm(int a, int b){ return a*b/gcd(a,b); } ... 阅读全文
posted @ 2014-12-22 13:15 zmiao 阅读(148) 评论(0) 推荐(0) 编辑
摘要:just use the java's printf function. It is like C's printf.System.out.printf("%.3f\n", x); 阅读全文
posted @ 2014-12-20 09:48 zmiao 阅读(105) 评论(0) 推荐(0) 编辑
摘要:Division by 3.发现一些规律:一个数的数字和相加能被三整除,那么这个数也能被3整除。(1)然后可以发现:连续三个整数并排在一起组成的数的数字和必然能被3整除。(2)最后通过(2)总结出:1.题目中的第3K个数,必然能被三整除。2.题目中的第3K + 1个数,其第2个数字到最末一个数字之和... 阅读全文
posted @ 2014-12-17 04:58 zmiao 阅读(125) 评论(0) 推荐(0) 编辑
摘要:it seems all stop methods of thread have been deprecated by java. so how to stop a thread then? it is actually simple, just use a boolean variable.pub... 阅读全文
posted @ 2014-12-06 07:49 zmiao 阅读(151) 评论(0) 推荐(0) 编辑