Gym - 100625G Getting Through 计算几何+并查集
题意:平面内给你一个y轴为左边界,宽度为w的长条形区域,区域内n个半径为r的圆,问你最大能够通过这个区域的圆的半径是多少。
思路:这题和POJ 3798差不是很多,感觉像是简化版。之前鲍佳提到过那个题,谈到过并查集,不过我没写过。知道并查集这题就很好想了,在圆与圆,圆与左右边界之间都连一条边,边长就是他们的距离。那么答案就是这些边中的一条了。现在将边排好序,从小到大加到并查集里面,每加一次find一下左边界和右边界是不是连到一起了,如果连起来了,那这条边就是答案,直接输出。最后还没连起来的话,就无解了。
#pragma comment(linker, "/STACK:1000000000")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define MAXN 1005
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
struct Circle
{
int x, y, r;
};
struct Node
{
int from, to;
double dis;
Node(int from, int to, double dis):from(from), to(to), dis(dis){};
};
Circle a[MAXN];
vector<Node> p;
int father[MAXN];
double GetDis(int u, int v)
{
double x = abs(a[u].x - a[v].x);
double y = abs(a[u].y - a[v].y);
double r = a[u].r + a[v].r;
return sqrt(x * x + y * y) - r;
}
int find(int x)
{
if(x == father[x]) return x;
father[x] = find(father[x]);
return father[x];
}
bool compare(Node a, Node b)
{
return a.dis < b.dis;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int T;
scanf("%d", &T);
while(T--){
int w;
scanf("%d", &w);
int n;
scanf("%d", &n);
if(n == ){
double ans = w;
ans /= ;
printf("%.7lf\n", ans);
continue;
}
for(int i = ; i <= n; i++){
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
}
for(int i = ; i <= n + ; i++){
father[i] = i;
}
p.clear();
for(int i = ; i <= n; i++){
for(int j = i + ; j <= n; j++){
p.push_back(Node(i, j, GetDis(i, j)));
}
}
for(int i = ; i <= n; i++){
p.push_back(Node(i, , a[i].x - a[i].r));
p.push_back(Node(i, n + , w - a[i].x - a[i].r));
}
n++;
sort(p.begin(), p.end(), compare);
int m = p.size();
double ans = ;
bool flag = false;
for(int i = ; i < p.size(); i++){
int x = find(p[i].from);
int y = find(p[i].to);
if(x == y) continue;
father[x] = y;
x = find();
y = find(n);
if(x == y && p[i].dis > ){
ans = p[i].dis;
flag = true;
break;
}
}
if(flag){
printf("%.7lf\n", ans / );
}
else{
printf("0\n");
}
}
}
Gym - 100625G Getting Through 计算几何+并查集的更多相关文章
- hdu 1558(计算几何+并查集)
Segment set Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1558 Segment set 计算几何+并查集★
#include <cstdio> #include <iostream> #include <string.h> using namespace std; ; # ...
- Gym - 101550A(Artwork 倒序+并查集)
题目: 思路: 1.对输入数据离线,先把所有的黑线都画出来,统计一下剩余的白色连通块的个数,dfs过程将一个连通块放到一个集合中. 2.倒着往前消去黑线,如果当前的块A是白块就看他的四周有没有白块:有 ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- Codeforces Gym 100463E Spies 并查集
Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...
- poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
- Gym 100814C Connecting Graph 并查集+LCA
Description standard input/output Statements Alex is known to be very clever, but Walter does not be ...
- 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 101173 F.Free Figurines(贪心||并查集)
原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一 ...
随机推荐
- linux在线添加硬盘、扫盘
1:查看scsi 硬盘设备[root@web02 ~]# ls /sys/class/scsi_host host0 host1 host2 2:检查本机现有硬盘 [root@web02 ~]# fd ...
- (52)KeyError错误
当出现:22KeyError: 'xxxxxx'这样的错误,可以肯定依赖出问题了,一般是你引用某个字段,但没有定义,又没有指定依赖的模块,最后找不到对应字段 解决方法:开发工具,把 xxxxxx 去搜 ...
- 2015 Multi-University Training Contest 3 hdu 5323 Solve this interesting problem
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 数组中出现一次的两个数(三个数)& 求最后一位bit为1
对于两个数,对于结果中,剩余bit1来异或区分. 下面的解法,非常精简: int lastBitOf1(int number) { ); } void getTwoUnique(vector<i ...
- poj-2758 Checking the Text
题意: 给定一个字符串,要求维护两种操作: I:在字符串中插入一个字符: Q:询问某两个位置開始的LCP. 插入操作<=200,字符串长度<=5w,查询操作<=2w: 题解: 第一道 ...
- 从头认识Spring-1.16 SpEl对集合的操作(1)-建立集合以及訪问集合的元素,以<util:list/>为例
这一章节我们来讨论一下怎样建立集合以及訪问集合的元素? 1.建立集合? (1)domain 蛋糕类: package com.raylee.my_new_spring.my_new_spring.ch ...
- 图像手工画效果【QT+OpenCV】
效果例如以下 [木雕]
- linux 抓包 tcpdump 简单应用
在linuxserver上,常常要定位网络问题,就须要用到抓包. 比如:tcpdump -X -s 0 host 10.17.81.22 and port 9999 -w /home/text.cap ...
- angularjs 标签指令
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- JNI中java类型的简写
在JNI中,当我们使用GetFieldID/GetStaticFieldID或GetMethodID/GetStaticMethodID及定义JNINativeMethod等时,我们需要表示成员变 ...