hdu 4723 How Long Do You Have to Draw(贪心)

How Long Do You Have to Draw

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 277    Accepted Submission(s): 110

Problem Description
There are two horizontal lines on the XoY plane. One is y1 = a, the other is y2 = b(a < b). On line y1, there are N points from left to right, the x-coordinate of which are x = c1, c2, ... , cN (c1 < c2 < ... < cN) respectively. And there are also M points on line y2 from left to right. The x-coordinate of the M points are x = d1, d2, ... dM (d1 < d2 < ... < dM) respectively.
Now you can draw segments between the points on y1 and y2 by some segments. Each segment should exactly connect one point on y1 with one point on y2.
The segments cannot cross with each other. By doing so, these segments, along with y1 and y2, can form some triangles, which have positive areas and have no segments inside them.
The problem is, to get as much triangles as possible, what is the minimum sum of the length of these segments you draw?
Input
The first line has a number T (T <= 20) , indicating the number of test cases.
For each test case, first line has two numbers a and b (0 <= a, b <= 104), which is the position of y1 and y2.
The second line has two numbers N and M (1 <= N, M <= 105), which is the number of points on y1 and y2.
The third line has N numbers c1, c2, .... , cN(0 <= ci < ci+1 <= 106), which is the x-coordinate of the N points on line y1.
The fourth line has M numbers d1, d2, ... , dM(0 <= di < di+1 <= 106), which is the x-coordinate of the M points on line y2.
Output
For test case X, output "Case #X: " first, then output one number, rounded to 0.01, as the minimum total length of the segments you draw.
Sample Input
1 0 1 2 3 1 3 0 2 4
Sample Output
Case #1: 5.66
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
Recommend
zhuyuanchen520

题意:两条平行线。各有n、m个点。要连一些线,两个端点各自是两条平行线上的点。而且不能交叉。

在取得最多三角形的情况下,求最小的总的线的长度。

题解:要保证有最多的三角形 得把全部的点都连上。这样先把两平行线的最左端两点先连上,再依次把两条平行线最左端没连的选距离小的连上。

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 100010using namespace std;double a[N],b[N];int main() {//freopen("test.in","r",stdin);int t;cin>>t;int ca=1;while(t--) {double y1,y2;scanf("%lf%lf",&y1,&y2);int n,m;scanf("%d%d",&n,&m);for(int i=0; i<n; i++) {scanf("%lf",&a[i]);}for(int j=0; j<m; j++) {scanf("%lf",&b[j]);}sort(a,a+n);sort(b,b+m);printf("Case #%d: ",ca++);if(n==1&&m==1) {printf("0.00\n");continue;}if(n==0||m==0) {printf("0.00\n");continue;}double ans=sqrt((y1-y2)*(y1-y2)+(a[0]-b[0])*(a[0]-b[0]));int l1=1,l2=1;while(l1<n&&l2<m) {double dis1=(y1-y2)*(y1-y2)+(a[l1]-b[l2-1])*(a[l1]-b[l2-1]);double dis2=(y1-y2)*(y1-y2)+(a[l1-1]-b[l2])*(a[l1-1]-b[l2]);if(dis1<dis2) {ans+=sqrt(dis1);l1++;} else {ans+=sqrt(dis2);l2++;}}while(l1<n) {double dis1=(y1-y2)*(y1-y2)+(a[l1]-b[l2-1])*(a[l1]-b[l2-1]);ans+=sqrt(dis1);l1++;}while(l2<m) {double dis2=(y1-y2)*(y1-y2)+(a[l1-1]-b[l2])*(a[l1-1]-b[l2]);ans+=sqrt(dis2);l2++;}printf("%.2f\n",ans );}return 0;
}

posted on 2017-05-01 10:29 mthoutai 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/mthoutai/p/6791366.html

hdu 4723 How Long Do You Have to Draw(贪心)相关推荐

  1. HDU多校1 - 6955 Xor sum(字典树+贪心)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,要求找到一段长度最短的区间,使得异或和大于等于 kkk,如果有多种答案,输出左端点最小的那个 题目分析:倒着维护一下后缀异或和,将后缀异或 ...

  2. HDU 4544 湫湫系列故事——消灭兔子 (贪心+优先队列)

    题目链接:HDU 4544 题面: 湫湫系列故事--消灭兔子 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K ...

  3. HDU - 5242 Game(树形dp+树链剖分/树上贪心+思维)

    题目链接:点击查看 题目大意:给出一棵包含n个节点的树,每个节点都有一个权值,整棵树的根是点1,问从点1开始向下一直走到叶子节点,可以走k次,怎么样走权值和最大,每个节点被走过一次后权值会变为0 题目 ...

  4. HDU 5037 Frog(2014年北京网络赛 F 贪心)

    开始就觉得有思路,结果越敲越麻烦...  题意很简单,就是说一个青蛙从0点跳到m点,最多可以跳l的长度,原有石头n个(都仅表示一个点).但是可能跳不过去,所以你是上帝,可以随便在哪儿添加石头,你的策略 ...

  5. *【HDU - 5711】Ingress(tsp旅行商问题,优先队列贪心,状压dp,floyd最短路,图论)

    题干: Brickgao, who profited from your accurate calculating last year, made a great deal of money by m ...

  6. 2013_chengdu_visit

    4716 A Computer Graphics Problem 签到题目,模拟. 4717 The Moving Points 求n个点的最大距离最小值,三分时间即可 4718 The LCIS o ...

  7. 贪 心 学用markdown

    贪 心 算 法 区间调度 区间划分 最小延迟调度 第一次比赛 [A题 hdu1283](http://acm.hdu.edu.cn/showproblem.php?pid=1283) [B题 hdu2 ...

  8. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  9. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  10. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

最新文章

  1. 【python】Python中给List添加元素的4种方法分享
  2. Exception in thread main java.lang.NullPointerException
  3. 用Java分割大型XML文件
  4. 图【数据结构F笔记】
  5. 网络:Server returned HTTP response code: 400(url中文)
  6. linux 行尾加字符串,linux – cat in expect脚本在字符串结尾添加新行
  7. Python入门到精通三天速成第一讲——创建自定义类
  8. 张北草原和锡林郭勒草原区别_草原:比您不知道的恶魔还强
  9. kali安装图像处理软件
  10. 计算机硬件基础 软考中级 网络工程师
  11. Proteus仿真-51单片机最小系统点亮LED
  12. R语言使用:符号生成向量数据、使用pie函数可视化饼图、自定义设置饼图色彩为彩虹色
  13. EVE LOM正式官宣杨洋成为品牌代言人
  14. 庐陵乡土“订婚”文化简记
  15. img标签无图片或者图片url错误时显示默认图片
  16. 4.2 char类型介绍
  17. Windows nc命令下载使用与使用bash建立反弹shell
  18. pb9 日历控件(源码)
  19. 正能量励志歌曲十大榜单盘点
  20. c语言中ioc有什么作用,IOC简介

热门文章

  1. 数据库 备份 压缩
  2. 挖掘经典:几乎被人遗忘的HTML七种用法
  3. 如何在Docker中安装MySQL
  4. JavaScript版MD5应用
  5. 批处理(bat)文件中输出中文乱码怎么办?
  6. 排序算法之三 选择排序(C++版本)
  7. bat复制文件到指定目录同名_利用bat让文件在指定时间自动进行备份
  8. php 简繁体字同时显示_(C++/php/Swift/Go/Ruby 篇)2020 年最火编程语言出炉!关键特性、普及程度、薪资全方位解读...
  9. d3.js 旋转图形_1.基础知识(3) Matlab绘制特殊的图形
  10. linux运维必学python吗_Python学习资源整理