上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 21 下一页
摘要: 有一个字符串,长度在1000000以内,求它最大的链节个数,即把s表示成s'+s'+s'······。求s'的个数。用KMP的思想,求出next数组,然后可以用手画方法发现从next[length(s)]到length(s)间的字符串可以不断向前推,只要这个长度能被总长度整除,它就是最大链节长度,否则就是1.View Code 1 program pku2406(input,output); 2 var 3 i,j : longint; 4 s : ansistring; 5 next : array[ 阅读全文
posted @ 2012-03-23 16:11 Codinginging 阅读(547) 评论(0) 推荐(0) 编辑
摘要: 数轴上有n个点,现在有c个点,放在n个点中的c个点中,让c个点中两点间最小距离最大。这个最大最小问题就真是二分答案了,然后贪心判定即可。加了一个pascal自身优化{$inline on}把140+ms拉到了90+ms。View Code 1 {$inline on} 2 program pku2456(input,output); 3 var 4 x : array[0..100010] of longint; 5 n,c : longint; 6 answer : longint; 7 procedure init; inline; 8 ... 阅读全文
posted @ 2012-03-22 11:26 Codinginging 阅读(359) 评论(0) 推荐(0) 编辑
摘要: 求一棵树的直径。题目没说数据范围,无论如何显然是O(n)的。这里用了dfs,先找任一点的最远点,再从这个最远点找一次最远点,后一个的两点距离就是答案。View Code 1 program pku1985(input,output); 2 type 3 node = ^link; 4 link = record 5 goal,w : longint; 6 next : node; 7 end; 8 var 9 l : array[0..50000] of node;10 d : ... 阅读全文
posted @ 2012-03-22 10:40 Codinginging 阅读(455) 评论(0) 推荐(0) 编辑
摘要: 给出算式{1/a = (1/b + 1/c) / (1 - 1/(b*c)}中的a,求算式中b和c使b+c最小.a,b,c均大于0。经过一系列的数学推导,可以得到b的范围是{0 < b <= a + sqrt(a^2 + 1)}又从某OIer的博客中看到令f(b)= b + c即f(b)=b + (ab + 1) / (b - a)求导得到f(b)' = 1 - (a^2 + 1) / (b - a)^2,在区间(a, a + sqrt(a^2 + 1))上恒小于0,所以f(b)单调递减。View Code 1 program pku1183(input,output); 阅读全文
posted @ 2012-03-21 16:32 Codinginging 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 有三维坐标中的16个点,然后又有若干点,求每一个点和前16个点中哪个更近。View Code 1 program pku1046(input,output); 2 type 3 node = record 4 x,y,z : longint; 5 end; 6 const 7 oo = 10000000; 8 var 9 color : array[1..16] of node;10 now : node;11 answer : byte;12 procedure init;13 var14 i : long... 阅读全文
posted @ 2012-03-21 16:16 Codinginging 阅读(165) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 21 下一页