上一页 1 2 3 4 5 6 7 ··· 13 下一页
摘要: 阅读全文
posted @ 2015-01-07 11:46 zmiao 阅读(108) 评论(0) 推荐(0) 编辑
摘要: bool prime(long n){ for(long i=2;i<=sqrt(n);i++){ if(n%i== 0){ return false; } } return true;}复杂度O(n*sqrt(n))如想要... 阅读全文
posted @ 2015-01-01 08:52 zmiao 阅读(102) 评论(0) 推荐(0) 编辑
摘要: 题目链接: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) 编辑
上一页 1 2 3 4 5 6 7 ··· 13 下一页