天天看点

HDU 4723 How Long Do You Have to Draw

There are two horizontal lines on the 

XoY plane. One is y 

1 = a, the other is y 

2 = b(a < b). On line y 

1, there are N points from left to right, the x-coordinate of which are x = c 

1, c 

2, ... , c 

N (c 

1 < c 

2 < ... < c 

N) respectively. And there are also M points on line y 

2 from left to right. The x-coordinate of the M points are x = d 

1, d 

2, ... d 

M (d 

1 < d 

2 < ... < d 

M) respectively. 

Now you can draw segments between the points on y 

1 and y 

2 by some segments. Each segment should exactly connect one point on y 

1 with one point on y 

2. 

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 <= 10 

4), which is the position of y 

1 and y 

2. 

The second line has two numbers N and M (1 <= N, M <= 10 

5), which is the number of points on y 

1 and y 

2. 

The third line has N numbers c 

1, c 

2, .... , c 

N(0 <= c 

i < c 

i+1 <= 10 

6), which is the x-coordinate of the N points on line y 

1. 

The fourth line has M numbers d 

1, d 

2, ... , d 

M(0 <= d 

i < d 

i+1 <= 10 

6), which is the x-coordinate of the M points on line y 

2.

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

#include<map>   
#include<set>  
#include<ctime>    
#include<cmath>   
#include<stack>
#include<queue>     
#include<string>    
#include<vector>    
#include<cstdio>        
#include<cstring>      
#include<iostream>    
#include<algorithm>        
#include<functional>    
using namespace std;
#define ms(x,y) memset(x,y,sizeof(x))        
#define rep(i,j,k) for(int i=j;i<=k;i++)        
#define per(i,j,k) for(int i=j;i>=k;i--)        
#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])        
#define inone(x) scanf("%d",&x)        
#define intwo(x,y) scanf("%d%d",&x,&y)        
#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)      
#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)     
#define lson x<<1,l,mid    
#define rson x<<1|1,mid+1,r    
#define mp(i,j) make_pair(i,j)    
#define ff first    
#define ss second    
typedef long long LL;
typedef pair<int, int> pii;
const int low(int x) { return x&-x; }
const int INF = 0x7FFFFFFF;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const double eps = 1e-8;
int T, cas = 1, n, m, a, b, c[N], d[N];

double get(int a, int b, int x, int y)
{
  return sqrt(1.0*(a - x)*(a - x) + 1.0*(b - y)*(b - y));
}

int main()
{
  for (inone(T); T--; cas++)
  {
    intwo(a, b); intwo(n, m);
    rep(i, 1, n) inone(c[i]);
    rep(i, 1, m) inone(d[i]);
    double ans = get(c[1], a, d[1], b);
    for (int i = 2, j = 2; i <= n || j <= m;)
    {
      if (i <= n && j <= m)
      {
        if (get(c[i], a, d[j - 1], b) < get(c[i - 1], a, d[j], b))
        {
          ans += get(c[i++], a, d[j - 1], b);
        }
        else
        {
          ans += get(c[i - 1], a, d[j++], b);
        }
      }
      else if (i <= n) ans += get(c[i++], a, d[m], b);
      else ans += get(c[n], a, d[j++], b);
    }
    printf("Case #%d: %.2lf\n", cas, ans);
  }
  return 0;
}