|
|
|
|
|
摘要:
我的第一道置换群论题目。开始的时候不知道这就是置换群,于是对着自己数据各种思考,居然想出来了标准算法的关键部分。当时的想法是这样的:从后向前扫描,如果这个数字没有在该在的位置上,那么就用最小的数与它交换,如果最小的数已经在了正确位置上,那么就考虑用次小数与它交换的情况。但这样的话,如果最小数和次小数都已经到了正确位置上呢?后来查找题解,才发现可以这样来做:从前向后扫描,哪个数没有在它该在的位置上,就找出它所在的群。通过下面这张图可以简单的看出群的定义:简单的说,一个群就是群内成员互相占领了其他人的位置,适当调换它们之间的位置可以让它们完全归位。把这个群全部归位的最小代价为Min(用群内最小数为 阅读全文
posted @ 2011-10-21 16:16
This_poet
阅读(590)
推荐(0)
编辑
摘要:
启发式搜索题目,裸的A*算法。启发式搜索中要选估价函数h,h函数必须满足h[i]<=到目标节点的实际距离,且在保证结果正确的情况下,h选得越大越好。广度优先搜索就是输在了估价函数上,它是一种特殊的启发式搜索,只不过启发函数为0罢了,所以广度优先搜索没有什么优化的余地。根据上述要求,我选择的估价函数是这个点目标的距离。维护一个优先队列,每次选择一个h[i]+dist[i]最小的节点进行扩展。当目标n被访问k次时,这时候dist[n]就是答案。代码:Program POJ2449;//By_ThispoetConst maxn=1000; maxm=100000;Var i,j,k,m,n, 阅读全文
posted @ 2011-10-21 15:48
This_poet
阅读(654)
推荐(0)
编辑
摘要:
状态设计:d[i,j](k)表示经过k条边的i到j的最短路。因为用了迭代的方法,所以可以省略。状态转移:d[i,j](M)=d[i,k](M >>1)+d[k,j](M>>1)代码:program poj3613;//By_thispoetconst maxn=105;var i,j,k,m,n,p,q,s,e,tot :longint; num :array[0..maxn*10]of longint; d,b,map :array[0..maxn,0..maxn]of longint;function hash(i:longint):longint;begin if 阅读全文
posted @ 2011-10-20 14:46
This_poet
阅读(397)
推荐(0)
编辑
摘要:
做法题目中已经给了,就是将{ 1,1 1,0}这个矩阵自乘n次。连续自乘n次的话就没意思了,那还不如直接上Fibonacci递推公式呢。矩阵的魅力就在于它可以上快速幂。因为矩阵乘法满足结合律么……代码:program poj3070;//By_Thispoetconst mol=10000; fib:array[1..2,1..2]of longint=((1,1),(1,0));type arr=array[1..2,1..2]of longint;var n :longint; ans :arr;function quickmi(p:longint):arr;var tmp... 阅读全文
posted @ 2011-10-20 11:31
This_poet
阅读(1291)
推荐(1)
编辑
摘要:
按照从左上开始、从右上开始、从左下开始、从右下开始四个顺序来Dp,记录路径,如果最小路径不唯一那么这个点的权值为0.极其考察细心和耐心,数据还是比较弱的……代码:program poj2329;const maxn=205;var i,j,m,p,q,n :longint; map,f,dp :array[0..maxn,0..maxn]of longint; rec,g :array[0..maxn,0..maxn]of record x,y:longint;end; function min(i,j:longint):longint;begin if i<j th... 阅读全文
posted @ 2011-10-19 22:46
This_poet
阅读(657)
推荐(1)
编辑
摘要:
算法讨论:这题陷阱比较多。首先,被所有牛欢迎,这说明所有的牛都要在一个连通图中,也就是将所给的边看成无向边的时候,所有点要在一个连通图中。这个我们用并查集来实现就可以了。强连通分量的求法就很简单了,正常的Tarjan就好了。求完强连通分量之后重新建图,找出新图上出度为0的点,那么在原图上在这个强连通分量中的点的个数就是答案。我的代码:program popular;//By_Thispoetconst maxn=10005;var i,j,k,m,n,p,q,total,time,size :longint; pr,la,ot,pre,other,last :array[0..maxn*5.. 阅读全文
posted @ 2011-10-18 16:29
This_poet
阅读(794)
推荐(1)
编辑
摘要:
没什么好说的了,用CL2姐姐的话说,题解满天飞,标程也满天飞……我的代码:Program eat;//by_ThispoetConst maxn=50005;Var father,data :Array[1..maxn]of Longint; ans,i,k,n,m,p,q :Longint; Function Root(i:Longint):Longint;var t:Longint;begin if father[i]=i then exit(i); t:=father[i]; father[i]:=Root(father[i]); data[i]:=(data[i]+data[... 阅读全文
posted @ 2011-10-08 18:02
This_poet
阅读(363)
推荐(0)
编辑
摘要:
Program poj1915;//By_ThispoetConst maxn=100000; ddx:Array[1..8]of Integer=(1,1,2,2,-1,-1,-2,-2); ddy:Array[1..8]of Integer=(2,-2,1,-1,2,-2,1,-1);Var i,j,k,m,n,p,q :Longint; h,t :Array[1..2]of Longint; step :Array[1..2,0..300,0..300]of Longint; v :Array[1..2,0..300,0..300]of Boole... 阅读全文
posted @ 2011-10-08 17:00
This_poet
阅读(862)
推荐(0)
编辑
摘要:
Program poj3414;//By_ThispoetConst maxn=100;Var v :Array[0..maxn,0..maxn]of Boolean; h,t,p,q :Longint; a,b,c,i,j :Longint; seq :Array[1..maxn*maxn*10]of record l,r,fa,did:Longint;end; ans :Array[0..maxn*maxn]of Longint; flag :Boolean; Function Check(i:Longint):Boolean;begin if (seq[i].l=c)o... 阅读全文
posted @ 2011-10-08 14:39
This_poet
阅读(565)
推荐(0)
编辑
摘要:
Program poj2488;//By_ThispoetConst ddx:Array[1..8]of Integer=(-2,-2,-1,-1,1,1,2,2); ddy:Array[1..8]of Integer=(-1,1,-2,2,-2,2,-1,1); maxn=26;Type rec=record ch:Char; num:Longint; end;Var i,j,m,n,o,p,q :Longint; v :Array[1..maxn,1..maxn]of Boolean; stack :Array[1..maxn*maxn]of rec; flag... 阅读全文
posted @ 2011-10-08 10:28
This_poet
阅读(712)
推荐(0)
编辑
|
|