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 【暴力枚举】的更多相关文章
- hdu 4932 Miaomiao's Geometry(暴力)
题目链接:hdu 4932 Miaomiao's Geometry 题目大意:在x坐标上又若干个点,如今要用若干条相等长度的线段覆盖这些点,若一个点被一条线段覆盖,则必须在这条线的左端点或者是右端点, ...
- hdu 4932 Miaomiao's Geometry(暴力枚举)
pid=4932">Miaomiao's Geometry ...
- HDU 4932 Miaomiao's Geometry(推理)
HDU 4932 Miaomiao's Geometry pid=4932" target="_blank" style="">题目链接 题意: ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- hdu4932 Miaomiao's Geometry (BestCoder Round #4 枚举)
题目链接:pid=4932" style="color:rgb(202,0,0); text-decoration:none">http://acm.hdu.edu ...
- BestCoder Round #4 Miaomiao's Geometry (暴力)
Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
随机推荐
- hdu2083
开始忘排序了. #include <stdio.h> #include <math.h> #include <algorithm> using namespace ...
- HDU-4417 Super Mario,划分树+二分!
Super Mario 这个题也做了一天,思路是很清晰,不过二分那里写残了,然后又是无限RE.. 题意:就是查询区间不大于k的数的个数. 思路:裸划分树+二分答案.将区间长度作为二分范围.这个是重点. ...
- oracle create directory
1.新建directory的语法 CREATE [OR REPLACE] DIRECTORY directory AS 'pathname'; 例如: create or replace direct ...
- BZOJ 3028 食物 ——生成函数
把所有东西的生成函数搞出来. 发现结果是x*(1-x)^(-4) 然后把(1-x)^(-4)求逆,得到(1+x+x^2+...)^4 然后考虑次数为n的项前的系数,就相当于选任意四个非负整数构成n的方 ...
- java date类型和calendar类型区别
Date类 在JDK1.0中,Date类是唯一的一个代表时间的类,但是由于Date类不便于实现国际化,所以从JDK1.1版本开始,推荐使用Calendar类进行时间和日期处理.这里简单介绍一下Date ...
- asp.net mvc 页面内容呈现Html.Raw HtmlString
asp.net mvc 页面内容呈现Html.Raw Html.Raw内容经过页面呈现,不呈现Html标签 @Html.Raw( File.ReadAllText(Server.MapPath(&qu ...
- 洛谷 [P3205] 合唱队
区间DP 手动模拟一下,我们发现本题就是一个左右加数的区间DP #include <iostream> #include <cstdio> #include <cstri ...
- XPath用法详解
1.XPath是什么 XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航(你可以理解为一种类似正则表达式的方法) 2.XPath的语法 表达式 ...
- hdu 4965 矩阵快速幂 矩阵相乘性质
Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Jav ...
- android调用邮件应用发送email
直接贴代码: Intent intent = new Intent(android.content.Intent.ACTION_SEND); // 附件 File file = new File(En ...