hdu3228Island Explorer

链接

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

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

注意N、M可能为0

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

  1 #include <iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<vector>
  7 #include<cmath>
  8 #include<queue>
  9 #include<set>
 10 using namespace std;
 11 #define N 50010
 12 #define LL long long
 13 #define INF 0xfffffff
 14 const double eps = 1e-8;
 15 const double pi = acos(-1.0);
 16 const double inf = ~0u>>2;
 17 struct point
 18 {
 19     double x,y;
 20     int id;
 21     point(double x=0,double y = 0):x(x),y(y) {}
 22 } p[N],q[N];
 23 struct node
 24 {
 25     int u,v;
 26     double w;
 27 } ed[N<<4];
 28 int fa[N],g;
 29 double t1[N],t2[N];
 30 point a,b,c,d;
 31 typedef point pointt;
 32 point operator -(point a,point b)
 33 {
 34     return point(a.x-b.x,a.y-b.y);
 35 }
 36 int dcmp(double x)
 37 {
 38     if(fabs(x)<eps) return 0;
 39     return x<0?-1:1;
 40 }
 41
 42 double dis(point a)
 43 {
 44     return sqrt(a.x*a.x+a.y*a.y);
 45 }
 46 bool cmmp(node ta,node tb)
 47 {
 48     return ta.w<tb.w;
 49 }
 50 int findx(int x)
 51 {
 52     if(x!=fa[x])
 53         fa[x] = findx(fa[x]);
 54     return fa[x];
 55 }
 56 void add(point ta,point tb)
 57 {
 58     ed[++g].u = ta.id;
 59     ed[g].v = tb.id;
 60     ed[g].w = dis(ta-tb);
 61 }
 62 int main()
 63 {
 64     // freopen("data.in","r",stdin);
 65     // freopen("data.out","w",stdout);
 66     int t,i,n,m;
 67     int kk = 0;
 68     cin>>t;
 69     while(t--)
 70     {
 71         scanf("%d%d",&n,&m);
 72         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);
 73         for(i = 0; i <= n+m ; i++)
 74             fa[i] = i;
 75         for(i = 0; i < n; i++)
 76         {
 77             scanf("%lf",&t1[i]);
 78
 79             // cout<<p[i].x<<" "<<p[i].y<<endl;
 80         }
 81         for(i = 0; i< m; i++)
 82         {
 83             scanf("%lf",&t2[i]);
 84
 85         }
 86         sort(t1,t1+n);
 87         sort(t2,t2+m);
 88         int h=0;
 89         for(i=0;i<n;i++)
 90             if(i==n-1||t1[i]!=t1[i+1])
 91                 t1[h++]=t1[i];
 92         n=h;
 93         h=0;
 94         for(i=0;i<m;i++)
 95             if(i==m-1||t2[i]!=t2[i+1])
 96                 t2[h++]=t2[i];
 97         m=h;
 98         for(i = 0; i < n;i++)
 99         {
100              p[i] = point(a.x*t1[i]+b.x*(1-t1[i]),a.y*t1[i]+b.y*(1-t1[i]));
101              p[i].id = i+1;
102         }
103         for(i = 0 ; i < m ; i++)
104         {
105             q[i] = point(c.x*t2[i]+d.x*(1-t2[i]),c.y*t2[i]+d.y*(1-t2[i]));
106             q[i].id = i+n+1;
107         }
108         g = 0;
109         double sum1 = 0,sum2 = 0;
110         for(i = 0 ; i < n-1 ; i++)
111         {
112             add(p[i],p[i+1]);
113             sum1+=dis(p[i]-p[i+1]);
114         }
115         for(i = 0 ; i < m-1 ; i++)
116         {
117             add(q[i],q[i+1]);
118             sum2+=dis(q[i]-q[i+1]);
119         }
120         if(n==0||m==0)
121         {
122
123             printf("Case #%d: %.3lf\n",++kk,sum1+sum2);
124             continue;
125         }
126         for(i = 0; i < n; i++)
127         {
128 //            point pp ;
129 //            if(dcmp(c.x-d.x)==0)
130 //            pp = point(c.x,p[i].y);
131 //            else
132 //            pp = dispoint(c,d,p[i]);
133 //            if(dcmp(pp.x-min(c.x,d.x))<=0||dcmp(pp.x-max(c.x,d.x))>=0)
134 //            {
135 //                add(i,n+1);
136 //                if(n+2<n+m)
137 //                add(i,n+2);
138 //                if(n+m-1>n+1)
139 //                add(i,n+m-1);
140 //                add(i,n+m);
141 //                continue;
142 //            }
143 //            int k = find(n+1,n+m,c,dis(pp-c));
144             // cout<<p[k].id<<" "<<pp.x<<" "<<pp.y<<endl;
145 //            add(i,k);
146 //            if(k!=n+1)
147 //            add(i,k-1);
148 //            if(k!=n+m)
149 //            add(i,k+1);
150             int l, r;
151             l = 0;
152             r = m-1;
153             while (r - l > 1)
154             {
155                 int mid1 = (r + l) >> 1;
156                 int mid2 = (mid1 + r) >> 1;
157                 if (dis(p[i]-q[mid1]) > dis(p[i]-q[mid2]))
158                     l = mid1;
159                 else
160                     r = mid2;
161             }
162 //            int k = find(1,n,a,dis(pp-a));
163             add(p[i],q[l]);
164             add(p[i],q[r]);
165             if(l-1>=0)
166                 add(p[i],q[l-1]);
167             if(r+1<=m-1)
168                 add(p[i],q[r+1]);
169         }
170         sort(ed+1,ed+g+1,cmmp);
171         int num = 0;
172         double sum = 0;
173         for(i = 1; i <= g; i++)
174         {
175             int tx = findx(ed[i].u);
176             int ty = findx(ed[i].v);
177             if(tx!=ty)
178             {
179                 fa[tx] = ty;
180                 num++;
181                 sum+=ed[i].w;
182             }
183         }
184         printf("Case #%d: %.3f\n",++kk,sum);
185     }
186     return 0;
187 }

hdu3228Island Explorer

时间: 2024-08-26 16:14:00

hdu3228Island Explorer的相关文章

How to Uninstall Internet Explorer 11 for Windows 7

Internet Explorer 11 is the newest version of Microsoft's web browser, but not everyone is a fan. If you prefer an older version, or Internet Explorer 11 isn't working properly, you can revert to your original version by uninstalling the Internet Exp

Windows下使用explorer批量下载文件

背景: 客户的环境是Windows Server 2008 R2,需要每个月安装补丁,但出于安全考虑,将微软的自动更新封掉了,以至于每次安装补丁只能手动下载然后安装. 有时候每次需要下载的补丁均比较多,而服务器上有没有迅雷,QQ旋风等下载工具,也不允许安装,所以每次均手动下载,十分麻烦. ==================我是分割线======================= 此方法是通过系统自带的explorer来实现批量下载. 众所周知,当你在我的电脑中输入一个链接时,explorer会

CVE-2010-0483分析 Microsoft Internet Explorer 6/7/8 - &#39;winhlp32.exe&#39; &#39;MsgBox()&#39; Remote Code Execution

相关资料:https://www.exploit-db.com/exploits/11615/ 目的是为了了解漏洞执行的流程. 根据资料准备服务端环境: 用一台win7当做是服务器,需要在win7上共享一个文件夹用于客户端访问.我的测试环境共享的文件夹是www. (1)启用Guest来宾账户,共享文件夹时将Guest添加读权限.此时在win7本机上应能访问,但在局域网的XP虚拟机无法访问  \\192.168.0.11\www\ (2)运行 secpol.msc 打开本地安全策略->本地策略->

activiti explorer源代码解读

请求通过ExplorerApplicationServlet(AbstractApplicationServlet.service()方法)进入web系统中. Activiti Explorer的应用程序为org.activiti.explorer.ExplorerApp, 其界面配置文件为Activiti\modules\activiti-webapp-explorer2\src\main\resources\activiti-ui-context.xml. 通过该配置文件创建主窗口org.a

小试X64 inline HOOK,hook explorer.exe---&gt;CreateProcessInternalW监视进程创建

原始函数是这样的 [cpp] view plain copy kernel32!CreateProcessInternalW: 00000000`7738e750 4c8bdc          mov     r11,rsp 00000000`7738e753 53              push    rbx 00000000`7738e754 56              push    rsi 00000000`7738e755 57              push    rd

Azure Storage Explorer 使用

有些时候我们在做迁移的时候为了保证数据安全,建议在不删除原有虚拟机的前提下,复制VHD文件,新建VM 工具:Azure Storage Explorer Download: http://azurestorageexplorer.codeplex.com/ 完成安装(此处省略) 打开storage explorer,配置存储账户 选择ADD Account 回到Azure portal,复制需要的信息 选择存储账号,点击管理密钥 将相关信息输入到Azure Storage Explorer 完成

码工的工具:全局鼠标手势与explorer文件管理器的tab插件

qttabbar与firefox的多标签浏览一样的功能,非常强大. 对于你我这样的需要打开n个文件夹的人来说,这东西太强大了. 看图片吧. 对于strokeit就跟firefox的手势一样的强大. 这时,就算chrome,ie没有手势,你也可以对它来定制后退,前进,关闭的手势了. 还是看图再自己定制试试吧. 码工的工具:全局鼠标手势与explorer文件管理器的tab插件,布布扣,bubuko.com

Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件。

Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件.至于原因请见 MSDN Blogs:<Internet Explorer and Connection Limits>,如何解除限制请见微软客户帮助与支持主页:<如何将 Internet Explorer 配置为可以同时进行两个以上的下载会话>.不管 Firefox 有多火,无可否认,IE 仍然是浏览器市场的老大.所以,在做系统架构时,不得不去考虑 IE  同时只能从同一域名下载两个文件的限制.如果超过

Explorer : 发布一个key-value存储系统,带有客户端和服务器端

Explorer 一个key-value存储系统,带有客户端和服务器端.使用非常方便. 使用B+树作为存储引擎,客户端和服务器端使用TCP协议进行通信. 代码采用C++实现,底层将客户端和服务器通信封装成了一个网络库,里面还有些还不错的实现可供看看,比如线程池.工作队列.Reactor设计模式实现等等. 项目地址:https://github.com/zinx2016/Explorer (欢迎大家给star  :) 编译方式 make 例子 首先启动服务器程序: 然后,运行客户端程序 : 首先,