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

题意:平面内给你一个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 计算几何+并查集的更多相关文章

  1. hdu 1558(计算几何+并查集)

    Segment set Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu 1558 Segment set 计算几何+并查集★

    #include <cstdio> #include <iostream> #include <string.h> using namespace std; ; # ...

  3. Gym - 101550A(Artwork 倒序+并查集)

    题目: 思路: 1.对输入数据离线,先把所有的黑线都画出来,统计一下剩余的白色连通块的个数,dfs过程将一个连通块放到一个集合中. 2.倒着往前消去黑线,如果当前的块A是白块就看他的四周有没有白块:有 ...

  4. 【转】并查集&MST题集

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

  5. Codeforces Gym 100463E Spies 并查集

    Spies Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Desc ...

  6. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

  7. Gym 100814C Connecting Graph 并查集+LCA

    Description standard input/output Statements Alex is known to be very clever, but Walter does not be ...

  8. 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 ...

  9. GYM 101173 F.Free Figurines(贪心||并查集)

    原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一 ...

随机推荐

  1. 学习《PythonWeb开发实战(董伟明)》中文PDF+源代码

    python可以用了进行数据分析,也可以进行Web开发,一般会使用django或者flask等进行开发. 国内介绍python web的书有写的不错的,推荐看看<PythonWeb开发实战> ...

  2. 【BZOJ 1192】[HNOI2006]鬼谷子的钱袋

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设k为最大的正整数满足 \(2^0+2^1+...+2^k<=m\) 如果\(m>2^0+2^1+...+2^k\) 那 ...

  3. Camera Calibration 相机标定:原理简介(二)

    2 针孔相机模型 常见的相机标定中,使用的相机多为针孔相机(Pinhole camera),也就是大家熟知的小孔成像理论.将其中涉及的坐标系之间的相互转换抽离出来,即为针孔相机模型的核心. 上图所示的 ...

  4. 集团公司(嵌入ETL工具)財务报表系统解决方式

    集团公司(嵌入ETL工具)財务报表系统解决方式 一.项目背景: 某集团公司是一家拥有100多家子公司的大型集团公司,旗下子公司涉及各行各业,包含:金矿.铜矿.房产.化纤等.因为子公司在业务上的差异.子 ...

  5. C++字节对齐与结构体大小计算

    转载注明出处:http://pppboy.blog.163.com/blog/static/30203796201082494026399/ 感谢原创博主的辛勤成果. 说明: 结构体的sizeof值, ...

  6. BZOJ 1336&1337最小圆覆盖

    思路: http://blog.csdn.net/commonc/article/details/52291822 (照着算法步骤写--) 已知三点共圆 求圆心的时候 就设一下圆心坐标(x,y) 解个 ...

  7. java操作文件的创建、删除、遍历

    java操作文件的创建.删除.遍历: package test; import java.io.File; import java.io.IOException; import java.util.A ...

  8. Python实现文件阅读功能(Python学习笔记)

    #!/usr/bin/python# Filename: filereader.pyimport sys def readfile(filename): '''Print a file to the ...

  9. DAG-背包九解-01背包

    饭卡:   电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够 ...

  10. 十一 模板匹配match template

    一.介绍 1.模板匹配 通俗讲就是以图找图,通过图中的一部分来找它在图中的位置(模板匹配就是在整个图像区域发现与给定子图像匹配的小块区域). 模板匹配是一种最原始.最基本的模式识别方法,研究某一特定对 ...