三分搜索-ZOJ LightBulb】的更多相关文章

开始算法基础学习的第一天 今天学习的内容是三分搜索 相对来说很基础的内容(还是觉得脑子不够用) 三分搜索主要用于凸函数查找极大值. (盗个图) 如图所示 若要查找该函数的最大值 可以考虑和二分法一样的思路,即用L,R两个端点去不断地逼近这个最大点 但是在这里仅用一个mid中值是不够的 因此添加了一个mmid = (mid+R)/2 判断函数在mid和mmid两点的大小就可以进一步判断极值存在于哪一段中 用一个便于理解的办法,我们分成以下两种情况来讨论: 1.mid,mmid在最大值的同一侧:这时…
Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate the harvest every year. But there is one thing you may not know that they hate walking so much that they would prefer to stay at hom…
You are given a sequence of n integers a1, a2, ..., an. Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible. The weakness of a sequence is defined as the maximum value of the poorness o…
http://codeforces.com/gym/101246/problem/J 题意:给出n个点坐标,要使这些点间距相同的话,就要移动这些点,问最少的需要的移动距离是多少,并输出移动后的坐标. 思路:昨晚比赛确定的一点就是通过X分搜索去枚举间距,使得最后的移动距离最短. 不过使用的是二分,而且写的时候也只枚举了起点和终点,后面想了要枚举所有的点,但时间来不及. 因为间距的单调不会使得答案单调,间距过大过小都会使得最后的移动距离不是最优,所以是使用三分而不是二分,顺便重温一下三分. whil…
http://codeforces.com/contest/782/problem/B 题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少. 思路:看上去很像二分搜索啊!枚举距离,判断是否有更少的时间,然后发现时间不随着距离单调增减,想起前两天被三分虐了一道题,那就是三分吧. 三分枚举距离,然后判断是否有更少的时间就可以了.比赛时候用了max函数还有精度开太大,超时了,索性直接循环100次. #include <bits/stdc++.h> usi…
Description "Hike on a Graph" is a game that is played on a board on which an undirected graph is drawn. The graph is complete and has all loops, i.e. for any two locations there is exactly one arrow between them. The arrows are coloured. There…
Line belt Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=3400 Mean: 给出两条平行的线段AB, CD,然后一个人在线段AB的A点出发,走向D点,其中,人在线段AB上的速度为P, 在线段CD上的速度为Q,在其他地方的速度为R,求人从A点到D点的最短时间. analyse: 经典的三分套三分. 首先在AB线段上三分,确定一个点,然后再在CD上三分,确定第二个点,计算出answer.也就是嵌套的三分搜索. Ti…
Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The local American Tire store sells fiberglass patching material only in square sheets. What is the smallest patch that Harry nee…
题意:       让你找到一个最小的圆柱去覆盖所有的竖直的线段.. 思路:       三分,直接去三分他的半径,因为想下,如果某个半径是最优值,那么 从R(MAX->now->MIN)是的 V肯定是先增大然后减小再增大,也就是满足凹凸性,所以可以三分,三分的时候根据当前的半径我们可以枚举每一个点,通过相似三角形去找到最大的H作为当前的H,然后根据V三分搜索就行了,对于low的初始值我赋的是 x_y平面上离原点距离最远的那个的距离+ 1e-9 ,防止被除数是0的情况.其他的没啥就是简单的三分…
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划  SOJ1162 I-Keyboard  SOJ1685 Chopsticks SOJ1679 Gangsters SOJ2096 Maximum Submatrix  SOJ2111 littleken bg SOJ2142 Cow Exhibition  SOJ2505 The County…