随笔分类 -  二分

EOJ 1126 最近点对(二分)
摘要:http://www.acm.cs.ecnu.edu.cn/problem.php?problemid=1126hdu 1007 http://acm.hdu.edu.cn/showproblem.php?pid=1007 求最近点对的距离。主要思想就是分治。先把n个点按x坐标排序,然后求左边n/2个和右边n/2个的最近距离,最后合并。合并要重点说一下,比较麻烦。 首先,假设点是n个,编号为1到n。我们要分治求,则找一个中间的编号mid,先求出1到mid点的最近距离设为d1,还有mid+1到n的最近距离设为d2。这里的点需要按x坐标的顺序排好,并且假设这些点中,没有2点在同一个位置。(若有,则 阅读全文

posted @ 2013-07-11 18:47 KimKyeYu 阅读(367) 评论(0) 推荐(0)

EOJ-2104 小强过桥
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=2104题意:给出n个节点之间路径的载重量,求出从s点到t点的可行的最大载重量。解法:n的数据量10^6,只能用邻接表存储,二分枚举最大载重量,用BFS遍历图判断是否合理,直到得到最优解。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include10 #include11 #include12 #include13 #include14 #include15 # 阅读全文

posted @ 2013-07-10 19:17 KimKyeYu 阅读(227) 评论(0) 推荐(0)

EOJ-1853 Mountain Walking
摘要:http://acm.cs.ecnu.edu.cn/problem.php?problemid=1853题意,从图的左上角走到图的右下角,寻找一条路径使得路径上的数字的MAX-MIN最小(不在意路径的长度)直接DFS剪枝比较难写(也感觉要T),看到差值最大为110,用二分枚举了差值(MAX-MIN)(从0到110),再枚举了图上的最小值。大意就是,先二分枚举差值m,再枚举图中可能的最小值a(从真·最小值到真·最大值),min=a,max=a+m。接着对起点DFS,看能否在min 2 #include 3 #include 4 #include 5 #include 6 #i 阅读全文

posted @ 2013-07-04 02:14 KimKyeYu 阅读(266) 评论(0) 推荐(0)

EOJ 1499 Gauss And Fibonacci
摘要:EOJ 1499 http://acm.cs.ecnu.edu.cn/problem.php?problemid=1499此题是要求F数列(Fibonacci)f[n]的前n项和S[n]; 注意到f[n] = f[n-1] + f[n-2],错项相加有 f[0] + f[1] + f[2] + ... + f[n-2]~ S[n-2] (f[0] = 0) +f[1] + f[2] + f[3] + ... + f[n-1] ~ S[n-1]-----------------------------------------------------=f[2] + f[3] + f[... 阅读全文

posted @ 2013-06-12 23:59 KimKyeYu 阅读(242) 评论(1) 推荐(1)

导航