您的位置:首页 > 其它

HDU4723-How Long Do You Have to Draw

2017-04-10 16:21 477 查看


How Long Do You Have to Draw

                                                                    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768
K (Java/Others)

                                                                                                 Total Submission(s): 417    Accepted Submission(s): 181


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 <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
#include <functional>

using namespace std;

#define LL long long
const int INF=0x3f3f3f3f;
const double exps=1e-8;

double c[100005],d[100005];

int main()
{
int t,n,m,cas=1;
double a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf",&a,&b);
double h=fabs(a-b)*fabs(a-b);
scanf("%d%d",&n,&m);
for (int i=0;i<n;i++) scanf("%lf",&c[i]);
for (int i=0;i<m;i++) scanf("%lf",&d[i]);
int x=0,y=0;
double len=0;
while(x<n&&y<m)
{
len+=sqrt(h+fabs(c[x]-d[y])*fabs(c[x]-d[y]));
if(x==n-1) y++;
else if(y==m-1) x++;
else
{
if(fabs(c[x]-d[y+1])<fabs(c[x+1]-d[y])) y++;
else x++;
}
}
printf("Case #%d: %.2f\n",cas++,len);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: