链接

给你两条线及两条线上的点,求最小生成树。

可以挨个枚举一条线上的点,三分出另一条线上离他最近的点进行连边。

注意N、M可能为0

debug了1天半,至今不知道原始二分版本错在哪里。。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 50010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
double x,y;
int id;
point(double x=,double y = ):x(x),y(y) {}
} p[N],q[N];
struct node
{
int u,v;
double w;
} ed[N<<];
int fa[N],g;
double t1[N],t2[N];
point a,b,c,d;
typedef point pointt;
point operator -(point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} double dis(point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
bool cmmp(node ta,node tb)
{
return ta.w<tb.w;
}
int findx(int x)
{
if(x!=fa[x])
fa[x] = findx(fa[x]);
return fa[x];
}
void add(point ta,point tb)
{
ed[++g].u = ta.id;
ed[g].v = tb.id;
ed[g].w = dis(ta-tb);
}
int main()
{
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
int t,i,n,m;
int kk = ;
cin>>t;
while(t--)
{
scanf("%d%d",&n,&m);
scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
for(i = ; i <= n+m ; i++)
fa[i] = i;
for(i = ; i < n; i++)
{
scanf("%lf",&t1[i]); // cout<<p[i].x<<" "<<p[i].y<<endl;
}
for(i = ; i< m; i++)
{
scanf("%lf",&t2[i]); }
sort(t1,t1+n);
sort(t2,t2+m);
int h=;
for(i=;i<n;i++)
if(i==n-||t1[i]!=t1[i+])
t1[h++]=t1[i];
n=h;
h=;
for(i=;i<m;i++)
if(i==m-||t2[i]!=t2[i+])
t2[h++]=t2[i];
m=h;
for(i = ; i < n;i++)
{
p[i] = point(a.x*t1[i]+b.x*(-t1[i]),a.y*t1[i]+b.y*(-t1[i]));
p[i].id = i+;
}
for(i = ; i < m ; i++)
{
q[i] = point(c.x*t2[i]+d.x*(-t2[i]),c.y*t2[i]+d.y*(-t2[i]));
q[i].id = i+n+;
}
g = ;
double sum1 = ,sum2 = ;
for(i = ; i < n- ; i++)
{
add(p[i],p[i+]);
sum1+=dis(p[i]-p[i+]);
}
for(i = ; i < m- ; i++)
{
add(q[i],q[i+]);
sum2+=dis(q[i]-q[i+]);
}
if(n==||m==)
{ printf("Case #%d: %.3lf\n",++kk,sum1+sum2);
continue;
}
for(i = ; i < n; i++)
{
// point pp ;
// if(dcmp(c.x-d.x)==0)
// pp = point(c.x,p[i].y);
// else
// pp = dispoint(c,d,p[i]);
// if(dcmp(pp.x-min(c.x,d.x))<=0||dcmp(pp.x-max(c.x,d.x))>=0)
// {
// add(i,n+1);
// if(n+2<n+m)
// add(i,n+2);
// if(n+m-1>n+1)
// add(i,n+m-1);
// add(i,n+m);
// continue;
// }
// int k = find(n+1,n+m,c,dis(pp-c));
// cout<<p[k].id<<" "<<pp.x<<" "<<pp.y<<endl;
// add(i,k);
// if(k!=n+1)
// add(i,k-1);
// if(k!=n+m)
// add(i,k+1);
int l, r;
l = ;
r = m-;
while (r - l > )
{
int mid1 = (r + l) >> ;
int mid2 = (mid1 + r) >> ;
if (dis(p[i]-q[mid1]) > dis(p[i]-q[mid2]))
l = mid1;
else
r = mid2;
}
// int k = find(1,n,a,dis(pp-a));
add(p[i],q[l]);
add(p[i],q[r]);
if(l->=)
add(p[i],q[l-]);
if(r+<=m-)
add(p[i],q[r+]);
}
sort(ed+,ed+g+,cmmp);
int num = ;
double sum = ;
for(i = ; i <= g; i++)
{
int tx = findx(ed[i].u);
int ty = findx(ed[i].v);
if(tx!=ty)
{
fa[tx] = ty;
num++;
sum+=ed[i].w;
}
}
printf("Case #%d: %.3f\n",++kk,sum);
}
return ;
}

hdu3228Island Explorer的更多相关文章

  1. 企业IT管理员IE11升级指南【1】—— Internet Explorer 11增强保护模式 (EPM) 介绍

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  2. 企业IT管理员IE11升级指南【2】—— Internet Explorer 11 对Adobe Flash的支持

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  3. 企业IT管理员IE11升级指南【6】—— Internet Explorer 11面向IT专业人员的常见问题

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  4. windows命令——explorer

    转至http://www.cnblogs.com/ymind/archive/2012/03/30/explorer-command-args.html 今天才知道,explorer原来可以这样用, ...

  5. Unable to extract 64-bitimage. Run Process Explorer from a writeable directory

    Unable to extract 64-bitimage. Run Process Explorer from a writeable directory When we run Process E ...

  6. Google调用explorer.exe打开本地文件

    给IE浏览器地址栏输个本地文件路径,会自动用explorer.exe打开,这个挺好的,但是IE对jQuery稍微高点的版本不怎么待见,只好自己给Google折腾一个调用explorer的功能----- ...

  7. Windows中explorer(图形壳)

    explorer是Windows程序管理器或者文件资源管理器. 用于管理Windows图形壳.(桌面和文件管理.) 删除该程序会导致Windows图形界面无法使用. explorer.exe进程是微软 ...

  8. WebSphere MQ Explorer的sqlserver的jdbc

    一.IBM WebSphere MQ7.0的jdbc支持数据库有: DB2 Informix Informix_With_Date_Format Microsoft_SQL_Server Oracle ...

  9. 更改eclipse的Package Explorer的字体

    说一个牛B的不像实力派的东西 — 更改eclipse的Package Explorer的字体1. 打开eclipse目录/Applications/Eclipse.app/Contents/Eclip ...

随机推荐

  1. iOS 用collectionview 做的无限图片滚动 广告banner适用

    使用方法见demo,bug未知,若有什么问题欢迎留言:) http://files.cnblogs.com/files/n1ckyxu/NickyScrollImageView.zip demo使用s ...

  2. SQL server的存储过程

    1.sp_databases 列出服务器上的所有数据库信息,包括数据库名称大小. 例:exec sp_databases 2.sp_helpdb 报告有关指定数据库或所有数据库的信息. 例: exec ...

  3. iOS cocospods Updating local specs repositories

    pod install --verbose --no-repo-update (在安装的时候) pod update --verbose --no-repo-update (在更新库的时候) 如果长时 ...

  4. iScroll.js和swiper.js

    最近系统地学习了iScroll.js和swiper.js,感觉它们在移动端特别好用:http://www.360doc.com/content/14/0724/11/16276861_39669990 ...

  5. 在CentOS 6.6下安装与配置mysql

    1.使用yum安装mysql yum list | grep mysql   //查看mysql信息 yum install mysql-server.x86_64 //安装mysql sudo ap ...

  6. php函数、php定义数组和数组遍历

    <?php //php函数//1.简单函数//四要素:返回类型,函数名,参数列表,函数体 /*function Show(){ echo "hello";} Show();* ...

  7. 成都PC网站建设需要考虑哪些费用呢

    亿合科技PC建设小编分享下:成都PC网站建设需要考虑哪些费用呢?随互联网的发展,越来越多人想建设自己网站,站长最关心的问题之一就是网站建设需要多少钱.每个网站建设的费用都是不一样的,但是都需要涵盖几个 ...

  8. Linux:SSH错误"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! "

    hadoop@master:~$ scp /home/hadoop/.ssh/authorized_keys node3:/home/hadoop/.ssh/ @@@@@@@@@@@@@@@@@@@@ ...

  9. C# 窗体(登录界面)

    首先拖动一个  lable(写用户名)  后面 跟一个Textbox 再lable(写密码) 后面 跟一个Textbox(需设置一下属性—行为—useSystemPasswordChar(默认输入的密 ...

  10. jvm基础笔记

    名词解释: 三类参数:标准参数(可能不会变的,java -help列出来的就是这类的),X参数(非标准化参数),XX参数(扩展参数). 所有XX 参数都以-XX开始,但后面出现的+-就不同了.+代表激 ...