BestCoder Round #4 之 Miaomiao'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
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.
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.
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.
题目大意:
#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)相关推荐
- 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 ...
- hdu4585 amp; BestCoder Round #1 项目管理(vector应用)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 项目管理 Time Limit: 2000/1000 MS (Java/Others) M ...
- 矩阵快速幂---BestCoder Round#8 1002
当要求递推数列的第n项且n很大时,怎么快速求得第n项呢? 可以用矩阵快速幂来加速计算. 我们可以用矩阵来表示数列递推公式 比如fibonacci数列 可以表示为 [f(n) f(n-1)] = [ ...
- 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II
题目传送门 1 /* 2 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 3 当然有可能两个数和超过p,那么an ...
- 贪心 BestCoder Round #39 1001 Delete
题目传送门 1 /* 2 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 3 否则再在tot里减去多余的即为答案 4 用set容器也可以做,思 ...
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
题目链接:ZCC loves straight flush 题面: ZCC loves straight flush Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 4932 BestCoder Round #4 1002
这题真是丧心病狂,引来今天的hack狂潮~ Miaomiao's Geometry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 字符串处理 BestCoder Round #43 1001 pog loves szh I
题目传送门 1 /* 2 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 3 */ 4 #include <cstdio&g ...
- BestCoder Round #90 Kblack loves flag
BestCoder Round #90 Kblack loves flag 问题描述 kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,kblack得到了一个n∗mn*mn∗ ...
最新文章
- javascript python 通信_Python通过websocket与js客户端通信示例分析
- RT-Thread 学习笔记(五)—— RTGUI代码解读
- GitHub如何删除一个repository(仓库)
- onenote怎么同步到电脑_OneNote“此分区文件似乎已损坏”的解决办法
- 详解Linux 五种IO模型
- Java输出流需要注意的几点细节
- 大剑无锋之mysql中的行转列如何写?【面试推荐】
- OpenShift 4 之Knative(1) - 创建Knative无服务器架构环境
- python multiprocessing遇到Can’t pickle instancemethod问题
- dxf文件预览打开编辑相关控件推荐
- 网吧电脑显示连不上服务器,Pubwin客户机连不上服务器怎么办?
- activity android:launchmode,谨慎设置启动Activity的launchMode
- zabbix安装详解
- DS4Windows(电脑PS4手柄控制器)v2.2.6 中文版
- python根据excel数据生成柱状图并导出成图片格式
- phpstudy升级mysql5.6_phpstudy升级mysql数据库
- C语言---数组排序
- 多项式求值秦九韶算法
- 广域网加速方案--Riverbed
- 【思源笔记】2.5.0 版本之后官方支持的第三方数据同步配置方式
热门文章
- python访问文件被拒绝_python – uWSGI服务器日志…权限被拒绝读取文件…哪个文件?...
- Pikachu实验重现2(Sql的注入)
- Pollard_rho大数质因数分解+拉格朗日四平方和定理(bzoj 2904: 平方和)
- 吴恩达神经网络和深度学习-学习笔记-22-误差分析
- python机器学习案例系列教程——推荐系统
- java执行cmd命令并获取返回结果字符串
- 贺利坚老师汇编课程46笔记:操作符offset取得标号的偏移地址
- 团队作业第六次-团队Github实战训练
- 关于 min_25 筛的入门以及复杂度证明
- volatile 线程内存模型