Gym - 100625G Getting Through 计算几何+并查集
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 计算几何+并查集相关推荐
- gym:Problem A Artwork(并查集思维题)
20162017-acmicpc-nordic-collegiate-programming-contest-ncpc-2016 Problem A Artwork 题目链接 http://codef ...
- 【转】并查集MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 ...
- hdu1558计算几何加并查集
不知道杭电题目分类是咋分的,这题我是在"匹配"里找到的,太假了.这明显是计算几何加并查集嘛.当然,并查集部分很简单,主要就是计算几何了,打了两个小时,我了个去,计算几何功底还是不行 ...
- Por Costel and the Match Gym - 100923H(经典种类并查集)
Por Costel and the Match Gym - 100923H 题目链接:https://vjudge.net/problem/Gym-100923H 题目: Oberyn Martel ...
- 【BFS】【并查集】【Tarjan】【LCA】Gym - 101173H - Hangar Hurdles
给你一张地图,给你q次询问,每次问你从A点到B点,最大能移动多大的箱子. 把每个点所能容纳的最大箱子求出来(BFS,八连通,一开始将所有边界点和障碍点入队).然后从大到小排序.然后用并查集将相邻(四联 ...
- 2018.08.02 hdu1558 Segment set(并查集+计算几何)
传送门 这个直接用并查集维护. 每加入一条线段就将它与其他能相交的集合合并,维护一个sizesize域表示每个集合的大小. 代码: #include<bits/stdc++.h> #def ...
- Friendly Group Gym - 102769F 2020(并查集)ccpc秦皇岛分站赛
题意: n个学生要组成一个小组参加会议(可以不参加), 1.对于每两个朋友(x ,y),如果他们俩都参加会议,该小组的友好价值将会增加 1:如果其中只有一位参加会议,则该组的友好价值将降低 1. 3. ...
- Gym 101915J(并查集)
传送门 题面: J. The Volcano Eruption time limit per test 5.0 s memory limit per test 64 MB input standard ...
- 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 ...
- Gym - 101194G Pandaria (并查集+倍增+线段树合并)
题意: 给定一个无向图.每个点有一种颜色.现在给定q个询问,每次询问x和w,求所有能通过边权值不超过w的边走到x的点的集合中,哪一种颜色的点出现的次数最多.次数相同时输出编号最小的那个颜色.强制在线. ...
最新文章
- 递归回溯解决八皇后问题
- Python 5种方法实现单例模式
- access 根据id删除数据_小程序云开发之数据库自动备份丨云开发101
- java访问其它服务器,一个Java Web应用程序是否可以在tomcat服务器的同一本地主机中调用另一个Java Web应用程序...
- Java基础入门笔记-添加包
- Linux(debian7)操作基础(十五)之systemd下lightdm免密登录
- .NET 6 Preview 4 已发布,这些新功能值得关注!
- vim 寄存器 操作_说实话,Intellij IDEA 自带的 Vim 插件真心不错。。。
- 【BZOJ2038】【2009国家集训队】小Z的袜子(hose) 分块+莫队
- 百度网盘也能BT下载ED2K
- 一个RSS阅读器的开源 ---- 邀请您加入开发队伍
- php和mysql学生报名系统_[源码和文档分享]基于PHP和MYSQL数据库实现的公共考试报名管理系统网站...
- 计算机485通讯原理,串口通信原理详解.ppt
- echarts地图放大拖拽
- python爬虫微信刷票_Python爬虫教程:你还在苦苦拉票吗?刷票小程序案例原理剖析!...
- Python3 requests模拟登录天善智能!
- 归并排序 代码 + 讲解
- 如何使用CNN进行物体识别和分类_基于CNN目标检测方法(RCNN,FastRCNN,FasterRCNN,MaskRCNN,YOLO,SSD)行人检测...
- 正则表达式教程及常用正则表达式
- 在安装Docker-ce的时候遇到报错
热门文章
- 微信支付金额为0.01分报错,和少一分钱的解决办法
- 阶段3 2.Spring_08.面向切面编程 AOP_1 AOP的概念
- 阶段3 2.Spring_06.Spring的新注解_6 Qualifier注解的另一种用法
- 正则表达式(三)操作符的运算优先级、全部符号的解释
- 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第1节 常用函数接口_4_使用Lambda优化日志案例...
- javascript焦点图自动播放
- Android 使用手机向手表安装任意.apk
- 使用Servlet技术~登录-02
- ASPNET--Basic Info
- .net(偏web) vs j2ee的一些框架选型