最后收到邮件说注意小数的问题!此代码并没有过所有数据,请读者参考算法,

自己再去修改一下吧!注意小数问题!

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 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 intersection of any two segments equals zero.

For example , point 2 is convered by [2 , 4] and not convered by [1 , 3]. [1 , 2] and [2 , 3] are legal segments , [1 , 2] and [3 , 4] are legal segments , but [1 , 3] and [2 , 4] are not (the length of intersection doesn't equals zero), [1 , 3] and [3 , 4] are not(not the same length).

Miaomiao wants to maximum the length of segements , please tell her the maximum length of segments.

For your information , the point can't coincidently at the same position.

Input
There are several test cases.
There is a number T ( T <= 50 ) on the first line which shows the number of test cases.
For each test cases , there is a number N ( 3 <= N <= 50 ) on the first line.
On the second line , there are N integers Ai (-1e9 <= Ai <= 1e9) shows the position of each point.
Output
For each test cases , output a real number shows the answser. Please output three digit after the decimal point.
Sample Input
3 3 1 2 3 3 1 2 4 4 1 9 100 10
Sample Output
1.000
2.000
8.000

Hint

For the first sample , a legal answer is [1,2] [2,3] so the length is 1. For the second sample , a legal answer is [-1,1] [2,4] so the answer is 2. For the thired sample , a legal answer is [-7,1] , [1,9] , [10,18] , [100,108] so the answer is 8.

题目大意:

类似于“区间覆盖”的问题!
在每组输入n个数,这n个数字是不同的,也就意味着,每两个值之间有差值。
题目要求用不计数的相等长度线段去覆盖这些点,并且呢,这些点必须在所在小线段的端点上。
举例说明(上面的第三组数据):
a数组: 1 9 100 10       先排一下序,
--->1 9 10 100 要覆盖这些点,并且这些点都必须在端点上,并且用于
覆盖的任何两条线段都不能有重复的部分。
b数组 8 1 90 ----> 相邻两数之间的间距,给b数组也排序。
把b数组的值遍历于a数组:思路是:a数组的第一个值和最后一个值可以往外扩展,则不必考虑了。
现在考虑a数组中间部分的数值,对于每个a[i](i=1--->=n-2)要满足:(a[i]+b[j]<a[i+1] || a[i]-b[j]>a[i-1] ),如果当前的b[j]满足所有的a[i],则说明b[j]可行,但是我们要找一个最大的b[j].
循环遍历一下b数组找到就行了。
Accepted的代码如下:(可供参考)
#include <stdio.h>
#include <string.h>
#include <algorithm>using namespace std;int main()
{int t;int n;int i, j;int a[60];int b[60], e;scanf("%d", &t);while(t--){scanf("%d", &n);for(i=0; i<n; i++){scanf("%d", &a[i] );}sort(a, a+n);e=0;for(i=1; i<n; i++){b[e++] = a[i] - a[i-1] ; }sort(b, b+n-1 );int max=-1;int flag;for(i=0; i<n-1; i++){flag=1; //初始化每个间距标记for(j=1; j<n-1; j++){   if(a[j]-b[i]<a[j-1] && a[j]+b[i]>a[j+1] ){flag=0;break;}}if(flag==1){if(b[i] >max ){max = b[i] ;}}}printf("%d", max );printf(".000\n");}return 0;
}

转载于:https://www.cnblogs.com/yspworld/p/3903330.html

BestCoder Round #4 之 Miaomiao's Geometry(2014/8/10)相关推荐

  1. 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 (Ja ...

  2. hdu4585 amp; BestCoder Round #1 项目管理(vector应用)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others)    M ...

  3. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [ ...

  4. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...

  5. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...

  6. HDU 5228 ZCC loves straight flush( BestCoder Round #41)

    题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others)    ...

  7. hdu 4932 BestCoder Round #4 1002

    这题真是丧心病狂,引来今天的hack狂潮~ Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  8. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...

  9. BestCoder Round #90 Kblack loves flag

     BestCoder Round #90 Kblack loves flag 问题描述 kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,kblack得到了一个n∗mn*mn∗ ...

最新文章

  1. javascript python 通信_Python通过websocket与js客户端通信示例分析
  2. RT-Thread 学习笔记(五)—— RTGUI代码解读
  3. GitHub如何删除一个repository(仓库)
  4. onenote怎么同步到电脑_OneNote“此分区文件似乎已损坏”的解决办法
  5. 详解Linux 五种IO模型
  6. Java输出流需要注意的几点细节
  7. 大剑无锋之mysql中的行转列如何写?【面试推荐】
  8. OpenShift 4 之Knative(1) - 创建Knative无服务器架构环境
  9. python multiprocessing遇到Can’t pickle instancemethod问题
  10. dxf文件预览打开编辑相关控件推荐
  11. 网吧电脑显示连不上服务器,Pubwin客户机连不上服务器怎么办?
  12. activity android:launchmode,谨慎设置启动Activity的launchMode
  13. zabbix安装详解
  14. DS4Windows(电脑PS4手柄控制器)v2.2.6 中文版
  15. python根据excel数据生成柱状图并导出成图片格式
  16. phpstudy升级mysql5.6_phpstudy升级mysql数据库
  17. C语言---数组排序
  18. 多项式求值秦九韶算法
  19. 广域网加速方案--Riverbed
  20. 【思源笔记】2.5.0 版本之后官方支持的第三方数据同步配置方式

热门文章

  1. python访问文件被拒绝_python – uWSGI服务器日志…权限被拒绝读取文件…哪个文件?...
  2. Pikachu实验重现2(Sql的注入)
  3. Pollard_rho大数质因数分解+拉格朗日四平方和定理(bzoj 2904: 平方和)
  4. 吴恩达神经网络和深度学习-学习笔记-22-误差分析
  5. python机器学习案例系列教程——推荐系统
  6. java执行cmd命令并获取返回结果字符串
  7. 贺利坚老师汇编课程46笔记:操作符offset取得标号的偏移地址
  8. 团队作业第六次-团队Github实战训练
  9. 关于 min_25 筛的入门以及复杂度证明
  10. volatile 线程内存模型