hdoj 4932 Miaomiao's Geometry 【暴力枚举】

题意:在一条直线上有n个点。取一长度差为x的区间。 规定点必须是区间的端点。 让你找出来最大的x

策略:rt

分析可得:两个相邻点之间的区间要么是两个点的差,要么就是两个点的差的一半,那我们就简单枚举一下就好了

排好序之后再枚举

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define M 200
using namespace std;
double s[M];
double init[M];
int t;
bool greedy(double max){
    int i;
    int flag = 0;
    for(i = 1; i < t-1; i ++){
        if((!flag&&init[i]-init[i-1] >= max)||(flag&&((init[i]-init[i-1])/2>=max||init[i]-init[i-1] == max))){  //flag == 0代表的意思是取右面的区间, flag = 1代表取左边的的区间。

在flag = 1的时候,能够取一半也能够取整个区间
            flag = 0;
        }
        else if(init[i+1]-init[i] >= max){
            flag = 1;
        }
        else return 0;
    }
    return 1;
}
void sear(int tot){
    int i;
    for(i = tot-1; i >= 0; i --){
        if(greedy(s[i])){
            printf("%.3lf\n", s[i]);
            break;
        }
    }
}
int main(){
    int i, n;
    scanf("%d", &n);
    while(n --){
        scanf("%d", &t);
        for(i = 0; i < t; i ++){
            scanf("%lf", &init[i]);
        }
        sort(init, init+t);
        int tot = 0;
        for(i = 1; i < t; i ++){
            s[tot++] = init[i]-init[i-1];
            s[tot] = s[tot-1]/2;
            tot++;
        }
        sort(s, s+tot);
        sear(tot);
    }
    return 0;
}

hdoj 4932 Miaomiao's Geometry 【暴力枚举】

时间: 2024-08-18 20:12:50

hdoj 4932 Miaomiao&#39;s Geometry 【暴力枚举】的相关文章

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

Miaomiao's Geometry                                                                              Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There are N point on X-axis . Miaomiao would like

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

枚举+贪心 HDOJ 4932 Miaomiao&#39;s Geometry

题目传送门 1 /* 2 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 3 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则往右边放, 4 判断一下,取最大值.这题二分的内容少 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #include <cmath> 10 using n

hdu 4932 Miaomiao&#39;s Geometry 暴力枚举

题目链接: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): 694    Accepted Submission(s): 180 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

BestCoder Round #4 Miaomiao&amp;#39;s Geometry (暴力)

Problem Description 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 le

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

Miaomiao's Geometry                                                                              Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There are N point on X-axis . Miaomiao would like

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两点

【HDOJ】4932 Miaomiao&#39;s Geometry

递归检测.因为dis数组开的不够大,各种wa.写了个数据发生器,果断发现错误,改完就过了. 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 6 using namespace std; 7 8 #define MAXN 55 9 10 int n; 11 double a[MAXN], dis[MAXN*2]; 12 char vi