题意:在一条直线上有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&#39;s Geometry 【暴力枚举】的更多相关文章

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

    题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...

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

    pid=4932">Miaomiao's Geometry                                                               ...

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

    HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...

  4. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

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

    题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...

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

    Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...

  7. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  8. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  9. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

随机推荐

  1. Java程序员---技能树

    计算机基础: 比如网络相关的知识. 其中就包含了 TCP 协议,它和 UDP 的差异.需要理解 TCP 三次握手的含义,拆.粘包等问题. 当然上层最常见的 HTTP 也需要了解,甚至是熟悉. 这块推荐 ...

  2. NYOJ 995 硬币找零

    硬币找零 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 在现实生活中,我们经常遇到硬币找零的问题,例如,在发工资时,财务人员就需要计算最少的找零硬币数,以便他们能从 ...

  3. zoj 2388 Beat the Spread!

    Beat the Spread! Time Limit: 2 Seconds      Memory Limit: 65536 KB Superbowl Sunday is nearly here. ...

  4. Tinkoff Challenge - Final Round (Codeforces Round #414, rated, Div. 1 + Div. 2) 继续跪一把

    这次的前三题挺简单的,可是我做的不快也不对. A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megab ...

  5. hdu2081

    #include <stdio.h> #include <malloc.h> int main(){ ]; char *p; int t; p=(); scanf(" ...

  6. Windows同步阿里云时间

    Ctrl+R打开cmd命令框 输入:gpedit.msc 计算机配置”—“管理模版”—“系统”—“Windows 时间服务”—“时间提供程序”—“配置 Windows NTP 客户端 双击打开配置 W ...

  7. Codeforces Round #358 (Div. 2)——C. Alyona and the Tree(树的DFS+逆向思维)

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. idea16使用maven命令clean、编译、打包jar或者war

    项目环境:idea16+jdk1.7+maven-3.3.9 项目说明:编写简单的java类,使用maven命令生成jar包,然后执行------->"java  -classpath ...

  9. 【Codeforces Round #503 (Div. 2)】

    A:https://www.cnblogs.com/myx12345/p/9843198.html B:https://www.cnblogs.com/myx12345/p/9843245.html ...

  10. 【BZOJ3611】大工程(虚树,DFS序,树形DP)

    题意:有一棵树,树有边权,有若干次询问,给出一些点,求: 1.这些点互相之间的距离之和 2.点对距离中的最大和最小值 n<=1000000 q<=50000并且保证所有k之和<=2* ...