hdu4932 Miaomiao's Geometry

这是一道搜索题,我们很容易得到目标值的上下界,然后就只能枚举了。

就是将x轴上的点排序之后从左到右依次考察每个点,每个点要么在线段的左端点,要么在线段的右端点。

点编号从0到n-1,从编号为1的点开始,在枚举的过程中不断压缩上界,有一种情况需要特别讨论,即哪种一条线段恰好覆盖相邻两个点的。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <map>
 5 #include <string>
 6 #include <vector>
 7 #include <set>
 8 #include <cmath>
 9 #include <ctime>
10 #pragma comment(linker, "/STACK:102400000,102400000")
11 #define lson (u << 1)
12 #define rson (u << 1 | 1)
13 #define rep(i, a, b) for(i = a; i < b; i++)
14 #define reps(i, a, b, c) for(i = a; i < b; i += c)
15 #define repi(i, a, b) for(i = a; i >= b; i--)
16 #define cls(i, j) memset(i, j, sizeof i)
17 using namespace std;
18 typedef __int64 ll;
19 const double eps = 1e-6;
20 const double pi = acos(-1.0);
21 const int maxn = 1e5 + 10;
22 const int maxm = 1050;
23 const int inf = 0x3f3f3f3f;
24 const ll linf = 0x3fffffffffffffff;
25 const ll mod = 1e9 + 7;
26
27 double a[55];
28 int n;
29 double maxi, mini;
30
31 double dfs(int u, int pre, double limit, int fixed){
32     //printf("%d %d\n",u, pre);
33     if(u >= n - 1) return limit;
34     if(limit <= mini) return mini;
35      double to_left = a[u] - a[pre];
36      double to_right = a[u + 1] - a[u];
37      double tem;
38      if(fixed){
39         if(to_left >= limit) return dfs(u + 1, u, limit, 1);
40         if(to_right >= 2 * limit || to_right == limit) return dfs(u + 2, u + 1, limit, 1);
41         if(to_right > limit) return dfs(u + 1, u + 1, limit, 1);
42         if(to_right < limit) return mini;
43      }
44      if(to_left >= limit) return dfs(u + 1, u, limit, 0);
45      double tem1 = dfs(u + 1, u, to_left, 0);
46      double tem2 = mini;
47      if(to_right >= 2 * limit) tem2 = dfs(u + 2, u + 1, limit, 0);
48      else{
49         if(to_right <= limit) tem2 = dfs(u + 2, u + 1, to_right, 1);
50         double tem3 = mini;
51         if(limit >= to_right / 2) tem3 = dfs(u + 2, u + 1, to_right / 2, 0);
52         tem2 = max(tem2, tem3);
53         tem3 = dfs(u + 1, u + 1, min(to_right, limit), 0);
54         tem3 = max(tem2, tem3);
55         if(limit < to_right / 2) tem3 = dfs(u + 2, u + 1, limit, 0);
56         tem2 = max(tem2, tem3);
57      }
58      return max(tem1, tem2);
59 }
60
61 int main(){
62    // freopen("in.txt", "r", stdin);
63     int T;
64     scanf("%d", &T);
65     while(T--){
66         scanf("%d", &n);
67         int i;
68         rep(i, 0, n) scanf("%lf", &a[i]);
69         sort(a, a + n);
70         a[n] = 0;
71         mini = (double)linf;
72         rep(i, 1, n) mini = min(mini, a[i] - a[i - 1]);
73         maxi = (double)linf;
74         rep(i, 1, n - 1) maxi = min(maxi, max(a[i + 1] - a[i], a[i] - a[i - 1]));
75         double ans = dfs(1, 0, maxi, 0);
76         printf("%.3f\n", ans);
77     }
78     return 0;
79 }

hdu4932 Miaomiao's Geometry

时间: 2024-11-11 08:12:39

hdu4932 Miaomiao's Geometry的相关文章

hdu4932 Miaomiao&#39;s Geometry (BestCoder Round #4 枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 410    Accepted Submission(s): 147 Problem Description There are N point

hdu4932 Miaomiao&amp;#39;s Geometry (BestCoder Round #4 枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 410    Accepted Submission(s): 147 Problem Description There are N point

HDU4932——二分——Miaomiao&#39;s Geometry

There are N point on X-axis . Miaomiao would like to cover them ALL by using segments with same length. There are 2 limits: 1.A point is convered if there is a segments T , the point is the left end or the right end of T.2.The length of the intersect

BestCoder4——Miaomiao&#39;s Geometry(水题。不知道放什么分类)

Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 10    Accepted Submission(s): 3 Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by us

hdu 4932 Miaomiao&#39;s Geometry 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4932 题目意思:给出 n 个点你,需要找出最长的线段来覆盖所有的点.这个最长线段需要满足两个条件:(1)每个点是某条线段的左端点或右端点   (2)任意两条线段之间的重叠部分的长度为0.(一个点重叠默认长度为0,即[1,2] , [2, 3] 视为合法).还有一点我来补充吧,就是这个最大长度是固定的,看第3组测试数据  1 9 100 10,[-7,1] , [1,9] , [10,18] , [1

BestCoder Round #4 之 Miaomiao&#39;s Geometry(2014/8/10)

Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 10    Accepted Submission(s): 3 Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by usi

hdu 4932 Miaomiao&#39;s Geometry(暴力)

题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,现在要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点,并且各个线段放的位置不能又重叠,求最大长度. 解题思路:这题有坑点,比赛的时候o(n)的算法去寻找两点之间最短距离.但起始这样是不行的,比如-1 0 10 12 18 20,这样维护过去的话,最短应该是12~18,长度为6,这段线段可以覆盖12和18的点,然后-1和20又在两端.于是只有0和10两点

HDU 4932 Miaomiao&#39;s Geometry(推理)

HDU 4932 Miaomiao's Geometry 题目链接 题意:给定x轴上一些点(不重复),现在要选一个线段,使得能放进这些区间中,保证线段不跨过点(即线段上只能是最左边或最右边是点),并且没有线段相交,求能放进去的最大线段 思路:推理一下,只有两点之间的线段,还有线段的一半可能符合题意,然后对于每种线段,去判断一下能不能成功放进去,这步用贪心,优先放左边,不行再放右边 代码: #include <cstdio> #include <cstring> #include &

hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】

题意:在一条直线上有n个点,取一长度差为x的区间, 规定点必须是区间的端点, 让你找出来最大的x 策略:rt 分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举一下就好了 排好序之后再枚举 代码: #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define M 200 using namespace std; do