08 2011 档案

Hash
摘要:转自:http://www.cnblogs.com/qianxun/archive/2011/07/03/2096773.html1.Hash介绍 Hash这个在实现某些功能的经常会用到的数据结构,在java和c++ 里面都有相应的封装好的数据结构:C++ STL Map java 有HashMap TreeMap。计算理论中,没有Hash函数的说法,只有单向函数的说法。所谓的单向函数,是一个复杂的定义,大家可以去看计算理论或者密码学方面的数据。用“人 类”的语言描述单向函数就是:如果某个函数在给定输入的时候,很容易计算出其结果来;而当给定结果的时候,很难计算出输入来,这就是单项函数。各种加密 阅读全文

posted @ 2011-08-24 19:50 lonelycatcher 阅读(2333) 评论(0) 推荐(0)

HDU 2522 1/n Hash
摘要:哎~~简直是坑爹的setbuf(stdout,NULL),不理解这个函数的机理,结果为杭电贡献了N次的time limit exceed,其实这道题目还是非常简单的,了解了除法的机制以后,就很好做了,注意余数相同时,循环节开始View Code 1 /* 2 * Author:lonelycatcher 3 * problem:hdu 2522 4 * Type:Hash 5 */ 6 #include <iostream> 7 #include<stdio.h> 8 #include<string.h> 9 #include<cstdlib>1 阅读全文

posted @ 2011-08-23 21:10 lonelycatcher 阅读(406) 评论(0) 推荐(0)

HDU 1800 Hash
摘要:这道题简化一些就是求输入相等的字符串的最大值,即最多有多少字符串相等,用map做的话相当简单,但是会超时,可能是用cin的原因,这里将字符串Hash到一个整数,然后就很简单了,注意这里有些地方需要注意的,即字符串前导零的处理!!View Code 1 /* 2 * Author:lonelycatcher 3 * problem:hdu 1800 4 * Type:字符串的Hash 5 */ 6 #include <iostream> 7 #include<limits.h> 8 #include<string.h> 9 #include<string 阅读全文

posted @ 2011-08-23 18:43 lonelycatcher 阅读(804) 评论(0) 推荐(1)

字符串Hash函数的比较
摘要:常用的字符串Hash函数还有ELFHash,APHash等等,都是十分简单有效的方法。这些函数使用位运算使得每一个字符都对最后的函数值产生影响。另外还有以MD5和SHA1为代表的杂凑函数,这些函数几乎不可能找到碰撞。常用字符串哈希函数有 BKDRHash,APHash,DJBHash,JSHash,RSHash,SDBMHash,PJWHash,ELFHash等等。对于以上几种哈希函数,我对其进行了一个小小的评测。Hash函数数据1数据2数据3数据4数据1得分数据2得分数据3得分数据4得分平均分BKDRHash20477448196.5510090.9582.0592.64APHash2347 阅读全文

posted @ 2011-08-23 15:17 lonelycatcher 阅读(1424) 评论(0) 推荐(0)

HDU 1496 equation 非常好的Hash
摘要:这道题目如果用一个四重循环的话应该会超时,可以将方程转换为一个等式,a*x1*x1+b*x2*x2=-(c*x3*x3+d*x4*x4);但是如何寻找适当x1,x2,x3,x4是这个等式成立呢,用Hash是一个不错的选择,将a*x1*x1+b*x2*x2映射到一个很大的数组(经过计算1000000即可),然后再对二重循环c*x3*x3+d*x4*x4的结果与相对应的Hash值相比较即可View Code 1 /* 2 * Author:lonelycatcher 3 * problem:hdu 1496 4 * Type:Hash 5 */ 6 #include <iostream> 阅读全文

posted @ 2011-08-23 11:43 lonelycatcher 阅读(410) 评论(0) 推荐(0)

<bitset>的用法整理
摘要:构造函数bitset<n> b;b有n位,每位都为0.参数n可以为一个表达式.如bitset<5> b0;则"b0"为"00000";bitset<n> b(unsigned long u);b有n位,并用u赋值;如果u超过n位,则顶端被截除如:bitset<5>b0(5);则"b0"为"00101";bitset<n> b(string s);b是string对象s中含有的位串的副本string bitval ( "10011" ); 阅读全文

posted @ 2011-08-22 18:46 lonelycatcher 阅读(444) 评论(0) 推荐(0)

HDU 1517
摘要:这道题真的是想了很久,一直束缚在SG函数上了,殊不知有的时候寻找P-position和N-position的规律更加方便。看了大牛的代码,寻找必胜区间,还有就是&位运算把自己搞糊涂了,惭愧。。。。以后判断奇偶数还是用%的好。。。转自:http://blog.pfan.cn/cruxd/22157.html这题好X难。 题目大概意思是:两人轮流乘一个2-9的数,从1开始乘,求谁的乘积先大于N。 如果是加法就好做了。凑到剩下的数能整除11,然后对称着加。问题是乘法。所以寻找必胜点(段)。以1000为例。 1000 | 999 ... 112 | 若占住999到112,则对手必胜。必须让对手 阅读全文

posted @ 2011-08-20 20:44 lonelycatcher 阅读(886) 评论(0) 推荐(0)

HDU 1536 poj 2960 博弈 SG函数
摘要:坑爹啊,一到简单的SG博弈题,折磨了我一个下午,竟然是在函数的递归调用中使用了全局的标志数组进行初始化。。。。View Code 1 /* 2 * Author:lonelycatcher 3 * Problem:HDU 1536 4 * Type:组合博弈,GS函数 5 */ 6 #include <iostream> 7 #include<stdio.h> 8 #include<algorithm> 9 #include<string.h>10 #include<cstdlib>11 using namespace std;12 阅读全文

posted @ 2011-08-20 17:49 lonelycatcher 阅读(324) 评论(0) 推荐(0)

HDU 1850 Being a Good Boy in Spring Festival
摘要:这是一道简单的Nim游戏组合博弈问题,对于Nim游戏的某个位置(x1,x2,x3...),当且仅当他们的部分nim和等于0(即各个值的异或),则当前位于P点,所以对于第一步,只要有一个xi大于其余元素的异或值,则xi可以改变成为其余元素的异或值(因为是大于),则这就是一种可能的选择View Code 1 /* 2 * Author:lonelycatcher 3 * problem:HDU 1850 Being a Good Boy in Spring Festival 4 * Type:博弈 5 */ 6 #include <iostream> 7 #include<std 阅读全文

posted @ 2011-08-20 11:29 lonelycatcher 阅读(202) 评论(0) 推荐(0)

HDU 2147 kiki's game 博弈
摘要:一道很简单的博弈题,找出P状态和N状态的规律即可View Code /* * Author:lonelycatcher * Problem:HDU 2147 * Type:组合博弈 */#include <iostream>#include<stdio.h>#include<cstdlib>using namespace std;int n,m;int main(){ while(scanf("%d %d",&n,&m)) { if(n==0&&m==0)break; if(!(n&1)) { pr 阅读全文

posted @ 2011-08-19 21:48 lonelycatcher 阅读(207) 评论(0) 推荐(0)

HDU 1847 cet-4 组合博弈
摘要:这道题也是一道简单的组合博弈题,状态图0 1 2 3 4 5 6 7 8 9.........P N N p N N p N N P........可以看出,所有3的倍数都是P状态的。。。View Code /* * Author:lonelycatcher * Problem:HDU 1847 * Type:简单组合博弈 */#include <iostream>#include<string.h>#include<string>#include<stdio.h>#include<cstdlib>using namespace st 阅读全文

posted @ 2011-08-19 20:22 lonelycatcher 阅读(225) 评论(0) 推荐(0)

HDU 1846 Brave Game 公平组合博弈
摘要:最近学了组合博弈的内容挺有意思的,小时牛刀,AC,(*^__^*) 嘻嘻……0是P状态,从1~M是N状态(至少有一种方法可以进入P状态),m+1是p状态(只能进入N状态)。。。。推理可知,m+1的倍数都是P 状态方法一,简单推理:View Code /* * Author:lonelycatcher * Problem:hdu 1846 * Type:博弈 */#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>using namespace std;in 阅读全文

posted @ 2011-08-19 14:41 lonelycatcher 阅读(276) 评论(0) 推荐(0)

Game theory初步
摘要:转自:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561002.html游戏1l 有两个游戏者:A和B。l 有21颗石子。l 两人轮流取走石子,每次可取1、2或3颗。l A先取。l 取走最后一颗石子的人获胜,即没有石子可取的人算输。如果剩下1、2或3颗石子,那么接下来取的人就能获胜;如果剩下4颗,那么无论接下来的人怎么取,都会出现前面这种情况,所以接下来取的人一定会输;如果剩下5、6或7颗石子,那么接下来取的人只要使得剩下4颗石子,他就能获胜。0,4,8,12,……都是下一个取石子者的必败状态。现在有21颗石子,21除以4的余数是1,所以先 阅读全文

posted @ 2011-08-19 11:48 lonelycatcher 阅读(199) 评论(0) 推荐(0)

寻找必败态——一类博弈问题的快速解法
摘要:转自:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561005.html博弈是信息学和数学试题中常会出现的一种类型,算法灵活多变是其最大特点,而其中有一类试题更是完全无法用常见的博弈树来进行解答。 寻找必败态即为针对此类试题给出一种解题思路。 此类问题一般有如下特点: 1、博弈模型为两人轮流决策的非合作博弈。即两人轮流进行决策,并且两人都使用最优策略来获取胜利。 2、博弈是有限的。即无论两人怎样决策,都会在有限步后决出胜负。 3、公平博弈。即两人进行决策所遵循的规则相同。 以下题目都属于这一类: POJ1740 A New Stone Ga 阅读全文

posted @ 2011-08-19 11:47 lonelycatcher 阅读(464) 评论(0) 推荐(1)

博弈论(二):Sprague-Grundy函数
摘要:转自:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561007.html上一期的文章里我们仔细研究了Nim游戏,并且了解了找出必胜策略的方法。但如果把Nim的规则略加改变,你还能很快找出必胜策略吗?比如说:有n堆石子,每次可以从第1堆石子里取1颗、2颗或3颗,可以从第2堆石子里取奇数颗,可以从第3堆及以后石子里取任意颗……这时看上去问题复杂了很多,但相信你如果掌握了本节的内容,类似的千变万化的问题都是不成问题的。现在我们来研究一个看上去似乎更为一般的游戏:给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动 阅读全文

posted @ 2011-08-19 11:46 lonelycatcher 阅读(352) 评论(0) 推荐(0)

博弈论(一):Nim游戏
摘要:转自:http://www.cnblogs.com/Knuth/archive/2009/09/05/1561008.html重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算。Nim游戏是博弈论中最经典的模型(之一?),它又有着十分简单的规则和无比优美的结论,由这个游戏开始了解博弈论恐怕是最合适不过了。Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG)。满足以下条件的游戏是I 阅读全文

posted @ 2011-08-19 11:45 lonelycatcher 阅读(479) 评论(0) 推荐(0)

POJ 1635 树的最小表示 Hash
摘要:树的同构问题,至今不知道什么叫做树的最小表示,参考了别人的代码:仅供自己参考。。Source CodeProblem:1635User:sunyanfeiMemory:748KTime:16MSLanguage:G++Result:AcceptedSource Code/* * problem:poj 1635 * Type:最小表示 */#include<iostream>#include<stdio.h>#include<string>#include<string.h>#include<algorithm>using names 阅读全文

posted @ 2011-08-17 22:40 lonelycatcher 阅读(823) 评论(0) 推荐(0)

ZOJ POJ 题目分类
摘要:ZOJ POJ 题目分类ZOJ题目分类初学者题:1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 2001 2022 2099 2104 2108 2172 2176 2201 2208 2321 2345 2351 2 阅读全文

posted @ 2011-08-17 20:27 lonelycatcher 阅读(1029) 评论(0) 推荐(1)

poj 1200 crazy search Hash
摘要:Problem:1200User:sunyanfeiMemory:30904KTime:63MSLanguage:G++Result:AcceptedSource Code/* * Author:lonelycatcher * Problem:poj 1200 crazy search * Type:Hash */#include <iostream>#include<string>#include<string.h>#include<stdio.h>using namespace std;char str[1000000];int hash[1 阅读全文

posted @ 2011-08-16 16:08 lonelycatcher 阅读(255) 评论(0) 推荐(0)

poj 1020 DFS +回溯
摘要:Source CodeProblem:1020User:sunyanfeiMemory:700KTime:32MSLanguage:G++Result:AcceptedSource Code/* * Problem:poj 1020 zoj 1411 * Type:DFS+回溯 */#include <iostream>#include<stdio.h>#include<string.h>using namespace std;int cake_size,cake_number,cuted_cakes;//cute_cakes是已经放好的蛋糕数int pie 阅读全文

posted @ 2011-08-15 20:42 lonelycatcher 阅读(307) 评论(0) 推荐(0)

poj 1564
摘要:Source Code/* * Author:lonelycatcher * problem:ZOJ 1711 * Type: DFS */#include<iostream>#include<stdio.h>#include<queue>#include<string>#include<string.h>using namespace std;int t,n;struct node{ int data; int preindex;};node lis[15];int OK,count;void printpath(int index 阅读全文

posted @ 2011-08-02 23:00 lonelycatcher 阅读(351) 评论(0) 推荐(0)

HDU 1041 递推 大数
摘要:递推:0->10 ; 1->01; 00->1010; 10->0110; 01->1001; 11->0101;假设a[i]表示第i 步时候的00的个数,由上面的可以看到,00是由01 得到的,所以只要知道a[i-1]的01的个数就能够知道a[i]的00的个数了,那a[i-1]怎么求呢,同样看推导,01由1和00 得到,而第i步1的个数是2^(i-1),所以a[i]=2^(i-3)+a[i-2];大数的话用java比较方便,用C++效率高点import java.io.*;import java.math.*;import java.util.*;publ 阅读全文

posted @ 2011-08-01 22:32 lonelycatcher 阅读(243) 评论(0) 推荐(0)

HDU 1040 排序 大水题一道
摘要:/* * Author:lonelycather * problem:hdu 1040 * Type:简单排序 */#include<stdio.h>#include <iostream>#include<algorithm>using namespace std;int cmp(const void* a,const void* b){ return *(int*)a-*(int*)b;}int N;int sequence[1000];int main(){ int T,i; cin>>T; while(T--) { cin>>N 阅读全文

posted @ 2011-08-01 15:39 lonelycatcher 阅读(339) 评论(0) 推荐(0)

HDU 1039 字符串处理
摘要:小水题一道,关键是第二个要求中状态的转移 hehhe/** Author:loneylycatcher* problem:hdu 1039* Type:字符串处理*/#include <iostream>#include<string.h>#include<stdio.h>#include<cstdlib>using namespace std;string s;int main(){ setbuf(stdout,NULL); int i; while(cin>>s) { if(s.compare("end")== 阅读全文

posted @ 2011-08-01 14:46 lonelycatcher 阅读(308) 评论(0) 推荐(0)

HDU 1036 字符串模拟题
摘要:这道字符串的题目其实并不简单,因为中间有许多的细节需要注意,注意这里的精度设计是四舍五入/* * Author:lonelycatcher * problem:HDU 1036 * Type:字符串处理 */#include <iostream>#include<string>#include<string.h>#include<stdio.h>using namespace std;int N,num;double dis;int main(){ setbuf(stdout,NULL); int i; cin>>N>>d 阅读全文

posted @ 2011-08-01 09:15 lonelycatcher 阅读(426) 评论(1) 推荐(0)

HDU 1035
摘要:简单模拟题,主要就是判别x和y 在不同方向下的坐标的变化/** Author:lonelycatcher* Problem:hdu 1035* Type:模拟,水题*/#include<iostream>#include<stdio.h>#include<string.h>using namespace std;struct node{char data;int visited;};node map[10][10];int row,colum,start;int main(){setbuf(stdout,NULL);int i,j,x,y,loop,step 阅读全文

posted @ 2011-08-01 08:18 lonelycatcher 阅读(337) 评论(0) 推荐(0)

HDU 1034 各种水,各种暴力都能过
摘要:/** Author:lonelycatcher* peoblem:hdu 1034* Type:模拟暴力各种暴力都能过*/#include<string.h>#include<stdio.h>#include<iostream>using namespace std;int OK,N;int candy[100000];int main(){setbuf(stdout,NULL);int i,steps; while(scanf("%d",&N)!=EOF) { steps=0; if(!N)break; for(i=1;i&l 阅读全文

posted @ 2011-08-01 08:16 lonelycatcher 阅读(447) 评论(0) 推荐(0)

HDU 1033 水题
摘要:题意还真的不好懂,摸索数据就出来了,注意顺时针和逆时针时候的方向变化/** Author:lonelycatcher* problem:hdu 1033* Type:水题*/#include<string.h>#include<iostream>#include<string>#include<stdio.h>#include<cstdlib>using namespace std;string command;int main(){while(cin>>command){printf("300 420 move 阅读全文

posted @ 2011-08-01 08:15 lonelycatcher 阅读(505) 评论(0) 推荐(0)

HDU 1032 水题
摘要:/** Author:lonelycatcher* problem:heu 1032* type:纯水题*/#include <iostream>#include<stdio.h>#include<string.h>#include<string.h>using namespace std;int fun(int x){int i=1;while(x!=1){if(x&1){x=3*x+1;}else{x=x>>1;}i++;}return i;}int main(){setbuf(stdout,NULL);int left, 阅读全文

posted @ 2011-08-01 08:14 lonelycatcher 阅读(228) 评论(0) 推荐(0)

HDU1031 排序题
摘要:/** Author:lonelycatcher* Problem:HDU 1031* Type:排序水题*/#include<iostream>#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;int N,M,K;struct node{double value;int index;};node nodes[1000000];int cmp1(const void* a,const void* b){node c=*(node*)a;node d=*( 阅读全文

posted @ 2011-08-01 08:12 lonelycatcher 阅读(488) 评论(0) 推荐(0)

导航