2013年10月16日

POJ 1006 中国剩余定理

摘要: 1 #include 2 int main() 3 { 4 // freopen("in.txt","r",stdin); 5 int p,e,i,d,kase=0; 6 while(scanf("%d%d%d%d",&p,&e,&i,&d)) 7 { 8 if(p==-1 && e == -1 && i == -1 && d== -1) break; 9 const int m1 = 23,m2 = 28,m3 = 33;10 const int M1 阅读全文

posted @ 2013-10-16 21:32 allh123 阅读(235) 评论(0) 推荐(0) 编辑

2013年9月10日

杭电 4712 汉明距

摘要: 暴力+剪枝,或者使用随机化算法,因为结果总是在0-20之间,所以任选两个求汉明距,它不是最终结果的概率应该不超过19/20,当随机生成10^5组数据时,求出的最小值不是最终结果的概率非常低。同时当结果为0或者1时能较快的判断出来,可以特判这两种情况。我的加了特判的代码: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N = 100005; 7 int a[N],n; 8 bool vis[(1 tmp) ans = tmp;35 }36 return ans;37 }... 阅读全文

posted @ 2013-09-10 16:41 allh123 阅读(212) 评论(0) 推荐(0) 编辑

2013年9月8日

rabin 素性检验 随机化算法

摘要: 1 #include 2 #include 3 #include 4 typedef long long int LL; 5 inline bool qpow(int a,int x) 6 { 7 int b = x-1,ans = 1; 8 while(b) 9 {10 if(b&1) ans = (LL)ans*a%x;11 a = (LL)a*a%x;12 b >>= 1;13 }14 if(ans == 1) return true;15 else return false;16 }... 阅读全文

posted @ 2013-09-08 21:54 allh123 阅读(257) 评论(0) 推荐(0) 编辑

2013年9月2日

HDU 4473 Exam 枚举

摘要: 原题转化为求a*b*c 的选法数。令a=i时,t = i这一种要删除,因为t = i则三个数都相等了,这种选法有3种,所以ans += 3*(t-1).ta,剩下的数的最大值s = n/(a*b),如果s b,则ans += 6*(s - b ).分类讨论时要不重复,不遗漏······贴代码: 1 #include 2 typedef long long int LL; 3 int main() 4 { 5 // freopen("in.txt","r",stdin); 6 LL n,ans; 阅读全文

posted @ 2013-09-02 15:12 allh123 阅读(211) 评论(0) 推荐(0) 编辑

HDU 4471 矩阵快速幂 Homework

摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4471解题思路,矩阵快速幂····特殊点特殊处理·····令h为计算某个数最多须知前h个数,于是写出方程:D =c1c2```c[h-1]c[h]10```0001```0000000010V[x] =f[x]f[x-1]``f[x-h+1]显然有V[x+1] = D*V[x].D是由系数行向量,一个(h-1)*(h-1)的单位矩阵,和一个(h-1)*1的0矩阵组成。V[x]是一个h行,1列的矩阵。初始条件为V 阅读全文

posted @ 2013-09-02 12:40 allh123 阅读(341) 评论(0) 推荐(0) 编辑

2013年8月31日

HDU 4465 数值计算,避免溢出

摘要: 数学,数值计算,求期望题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4465题目描述:有两个盒子,每个中有n个糖果,(n<10^5)每次任选一个盒子,如果有糖就吃掉,没糖就去开另一个盒子。选中盒子1的概率为p,选中盒子2的概率为1-p.问当发现一个盒子里没有糖时,另一个盒子中糖果的个数的数学期望。解法:利用数学期望的定义,结果一共为x = 0,1,2,```,n.如果知道p(x),求sum(x*p(x))即可。为方便计算,设吃掉了i个糖果时发现盒子空。则有x = 2*n-i时,p[x] = C(i,n)*[p^(n+1)*q^(i-n)+q 阅读全文

posted @ 2013-08-31 17:12 allh123 阅读(221) 评论(0) 推荐(0) 编辑

2013年8月30日

LA 3938 动态最大连续和 线段树

摘要: 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1939来自:刘汝佳大白书P201.解题思路:构造一棵线段树,其中每个结点维护三个值,记录最大前缀和,最大后缀和最大连续和。最大连续和要么完全在左段,要么完全在右段,要么在跨越中线。就是会是左段的最大后缀和+右段的最大前缀和。。。。代码也是刘汝佳写的哦代码: 1 // LA3938 Ray, Pass me the dishes! 2 // Rujia Li 阅读全文

posted @ 2013-08-30 16:50 allh123 阅读(682) 评论(0) 推荐(0) 编辑

2013年8月29日

UVA 11235 频繁出现的数值 RMQ

摘要: 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2176RMQ,就是范围最小值的缩写,这个算法是Tarjan 的 Sparse-Table 算法,复杂度为O(n*log(n)).就是用数组d[i][j]表示范围[i,i+2^j-1]中的最小值。然后有递推式d[i][j] = min(d[i][j-1],d[i+2^(j-1)][j-1]).有边界条件d[i][0] = A[i].然后就能求出所有的d[i][j].查询时只 阅读全文

posted @ 2013-08-29 18:40 allh123 阅读(242) 评论(0) 推荐(0) 编辑

LA 4329 ping-pong树状数组

摘要: 题目链接:刘汝佳,大白书,P197.枚举裁判的位置,当裁判为i时,可以有多少种选法,如果已经知道在位置i之前有ci个数比ai小,那么在位置i之前就有i-1-ci个数比ai大。在位置i之后有di个数比ai小,那么在位置i之后就有n-i-di个数比ai大。这样,选法数有ci*(n-i-di)+di*(i-1-ci).注意到ai的值各不相同且ai的值最大不超过10^5,那样就可以用v[a[i]]表示a[i]是否已经存在,这样当顺时针扫描的时候,每次更新v[a[i]] = 1;//表示已经存在。比ai小的数的个数就是sum(v[j]) j 2 #include 3 #include 4 using n 阅读全文

posted @ 2013-08-29 16:34 allh123 阅读(343) 评论(0) 推荐(0) 编辑

2013年8月28日

LA 3027 合作网络 并查集

摘要: 题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1028比较简单,用数组d[i]表示结点i和祖先结点的距离,查询时压缩路径并更新d[]数组。刘汝佳大白书(P193):贴代码: 1 #include 2 #include 3 const int N = 20004; 4 int pa[N],d[N]; 5 int findset(int x) 6 { 7 if(pa[x] == -1) return x; 阅读全文

posted @ 2013-08-28 19:26 allh123 阅读(189) 评论(0) 推荐(0) 编辑

导航