http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contest-bapc-13-en.pdf

题意:平面内给你一个y轴为左边界,宽度为w的长条形区域,区域内n个半径为r的圆,问你最大能够通过这个区域的圆的半径是多少。

思路:这题和POJ 3798差不是很多,感觉像是简化版。之前鲍佳提到过那个题,谈到过并查集,不过我没写过。知道并查集这题就很好想了,在圆与圆,圆与左右边界之间都连一条边,边长就是他们的距离。那么答案就是这些边中的一条了。现在将边排好序,从小到大加到并查集里面,每加一次find一下左边界和右边界是不是连到一起了,如果连起来了,那这条边就是答案,直接输出。最后还没连起来的话,就无解了。

  1 #pragma comment(linker, "/STACK:1000000000")
  2 #include <iostream>
  3 #include <cstdio>
  4 #include <fstream>
  5 #include <algorithm>
  6 #include <cmath>
  7 #include <deque>
  8 #include <vector>
  9 #include <queue>
 10 #include <string>
 11 #include <cstring>
 12 #include <map>
 13 #include <stack>
 14 #include <set>
 15 #define LL long long
 16 #define MAXN 1005
 17 #define INF 0x3f3f3f3f
 18 #define eps 1e-8
 19 using namespace std;
 20 struct Circle
 21 {
 22     int x, y, r;
 23 };
 24 struct Node
 25 {
 26     int from, to;
 27     double dis;
 28     Node(int from, int to, double dis):from(from), to(to), dis(dis){};
 29 };
 30 Circle a[MAXN];
 31 vector<Node> p;
 32 int father[MAXN];
 33 double GetDis(int u, int v)
 34 {
 35     double x = abs(a[u].x - a[v].x);
 36     double y = abs(a[u].y - a[v].y);
 37     double r = a[u].r + a[v].r;
 38     return sqrt(x * x + y * y) - r;
 39 }
 40 int find(int x)
 41 {
 42     if(x == father[x]) return x;
 43     father[x] = find(father[x]);
 44     return father[x];
 45 }
 46 bool compare(Node a, Node b)
 47 {
 48     return a.dis < b.dis;
 49 }
 50 int main()
 51 {
 52 #ifndef ONLINE_JUDGE
 53     freopen("in.txt", "r", stdin);
 54     //freopen("out.txt", "w", stdout);
 55 #endif // OPEN_FILE
 56     int T;
 57     scanf("%d", &T);
 58     while(T--){
 59         int w;
 60         scanf("%d", &w);
 61         int n;
 62         scanf("%d", &n);
 63         if(n == 0){
 64             double ans = w;
 65             ans /= 2;
 66             printf("%.7lf\n", ans);
 67             continue;
 68         }
 69         for(int i = 1; i <= n; i++){
 70             scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
 71         }
 72         for(int i = 0; i <= n + 1; i++){
 73             father[i] = i;
 74         }
 75         p.clear();
 76         for(int i = 1; i <= n; i++){
 77             for(int j = i + 1; j <= n; j++){
 78                 p.push_back(Node(i, j, GetDis(i, j)));
 79             }
 80         }
 81         for(int i = 1; i <= n; i++){
 82             p.push_back(Node(i, 0, a[i].x - a[i].r));
 83             p.push_back(Node(i, n + 1, w - a[i].x - a[i].r));
 84         }
 85         n++;
 86         sort(p.begin(), p.end(), compare);
 87         int m = p.size();
 88         double ans = 0;
 89         bool flag = false;
 90         for(int i = 0; i < p.size(); i++){
 91             int x = find(p[i].from);
 92             int y = find(p[i].to);
 93             if(x == y) continue;
 94             father[x] = y;
 95             x = find(0);
 96             y = find(n);
 97             if(x == y && p[i].dis > 0){
 98                 ans = p[i].dis;
 99                 flag = true;
100                 break;
101             }
102         }
103         if(flag){
104             printf("%.7lf\n", ans / 2);
105         }
106         else{
107             printf("0\n");
108         }
109     }
110 }

转载于:https://www.cnblogs.com/macinchang/p/4718147.html

Gym - 100625G Getting Through 计算几何+并查集相关推荐

  1. gym:Problem A Artwork(并查集思维题)

    20162017-acmicpc-nordic-collegiate-programming-contest-ncpc-2016 Problem A Artwork 题目链接 http://codef ...

  2. 【转】并查集MST题集

    转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 ...

  3. hdu1558计算几何加并查集

    不知道杭电题目分类是咋分的,这题我是在"匹配"里找到的,太假了.这明显是计算几何加并查集嘛.当然,并查集部分很简单,主要就是计算几何了,打了两个小时,我了个去,计算几何功底还是不行 ...

  4. Por Costel and the Match Gym - 100923H(经典种类并查集)

    Por Costel and the Match Gym - 100923H 题目链接:https://vjudge.net/problem/Gym-100923H 题目: Oberyn Martel ...

  5. 【BFS】【并查集】【Tarjan】【LCA】Gym - 101173H - Hangar Hurdles

    给你一张地图,给你q次询问,每次问你从A点到B点,最大能移动多大的箱子. 把每个点所能容纳的最大箱子求出来(BFS,八连通,一开始将所有边界点和障碍点入队).然后从大到小排序.然后用并查集将相邻(四联 ...

  6. 2018.08.02 hdu1558 Segment set(并查集+计算几何)

    传送门 这个直接用并查集维护. 每加入一条线段就将它与其他能相交的集合合并,维护一个sizesize域表示每个集合的大小. 代码: #include<bits/stdc++.h> #def ...

  7. Friendly Group Gym - 102769F 2020(并查集)ccpc秦皇岛分站赛

    题意: n个学生要组成一个小组参加会议(可以不参加), 1.对于每两个朋友(x ,y),如果他们俩都参加会议,该小组的友好价值将会增加 1:如果其中只有一位参加会议,则该组的友好价值将降低 1. 3. ...

  8. Gym 101915J(并查集)

    传送门 题面: J. The Volcano Eruption time limit per test 5.0 s memory limit per test 64 MB input standard ...

  9. Tree Restoration Gym - 101755F (并查集)

    There is a tree of n vertices. For each vertex a list of all its successors is known (not only direc ...

  10. Gym - 101194G Pandaria (并查集+倍增+线段树合并)

    题意: 给定一个无向图.每个点有一种颜色.现在给定q个询问,每次询问x和w,求所有能通过边权值不超过w的边走到x的点的集合中,哪一种颜色的点出现的次数最多.次数相同时输出编号最小的那个颜色.强制在线. ...

最新文章

  1. 递归回溯解决八皇后问题
  2. Python 5种方法实现单例模式
  3. access 根据id删除数据_小程序云开发之数据库自动备份丨云开发101
  4. java访问其它服务器,一个Java Web应用程序是否可以在tomcat服务器的同一本地主机中调用另一个Java Web应用程序...
  5. Java基础入门笔记-添加包
  6. Linux(debian7)操作基础(十五)之systemd下lightdm免密登录
  7. .NET 6 Preview 4 已发布,这些新功能值得关注!
  8. vim 寄存器 操作_说实话,Intellij IDEA 自带的 Vim 插件真心不错。。。
  9. 【BZOJ2038】【2009国家集训队】小Z的袜子(hose) 分块+莫队
  10. 百度网盘也能BT下载ED2K
  11. 一个RSS阅读器的开源 ---- 邀请您加入开发队伍
  12. php和mysql学生报名系统_[源码和文档分享]基于PHP和MYSQL数据库实现的公共考试报名管理系统网站...
  13. 计算机485通讯原理,串口通信原理详解.ppt
  14. echarts地图放大拖拽
  15. python爬虫微信刷票_Python爬虫教程:你还在苦苦拉票吗?刷票小程序案例原理剖析!...
  16. Python3 requests模拟登录天善智能!
  17. 归并排序 代码 + 讲解
  18. 如何使用CNN进行物体识别和分类_基于CNN目标检测方法(RCNN,FastRCNN,FasterRCNN,MaskRCNN,YOLO,SSD)行人检测...
  19. 正则表达式教程及常用正则表达式
  20. 在安装Docker-ce的时候遇到报错

热门文章

  1. 微信支付金额为0.01分报错,和少一分钱的解决办法
  2. 阶段3 2.Spring_08.面向切面编程 AOP_1 AOP的概念
  3. 阶段3 2.Spring_06.Spring的新注解_6 Qualifier注解的另一种用法
  4. 正则表达式(三)操作符的运算优先级、全部符号的解释
  5. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_4_使用Lambda优化日志案例...
  6. javascript焦点图自动播放
  7. Android 使用手机向手表安装任意.apk
  8. 使用Servlet技术~登录-02
  9. ASPNET--Basic Info
  10. .net(偏web) vs j2ee的一些框架选型