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. nginx upstream

    nginx转发http和tcp http转发 upstream goforit_201 { server 172.168.10.10:201; } server { listen 201; serve ...

  2. WPF 一个空的 WPF 程序有多少个窗口

    原文:WPF 一个空的 WPF 程序有多少个窗口 好多小伙伴说 WPF 的程序有五个窗口,但是我尝试使用了 EnumThreadWindows 去获取的时候居然拿到了 10 多个窗口 在 WPF 内部 ...

  3. Android 之 Eclipse没法生成R文件

    这几天被Eclipse整哭了.也怪自己手贱把appcompat_v7给删了. Eclipse创建project假设是兼容4.0下面,会多生成一个projectappcompat_v7,例如以下图: 这 ...

  4. Linux/UNIX线程(1)

    线程(1) 本文将介绍怎样使用多个控制线程在单个进程环境中运行多个任务. 一个进程中的全部线程都能够訪问该进程的组成部件(如文件描写叙述符和内存). 线程包含了表示进程内运行环境必须的信息,当中包含进 ...

  5. Pycharm-连接服务器

  6. SSRS 报表 如何匿名查看

    SSRS 报表 如何匿名查看 昨晚一直研究怎么能匿名访问报表然后给客户看呢? 研究了好几种办法 我试过的分为三种,其中推荐我认为相对可控一点. .修改SSRS配置文件来禁止他验证登陆用户权限 操作过的 ...

  7. 最简单的TCP程序

    网络编程里面最简单的一个tcp程序,把一个文件从客户端上传到服务器端,上传成功后服务器端提示上传完成.代码不多,一个服务端和一个客户端. 服务端代码: import java.io.FileOutpu ...

  8. 上传golang 版本SDK

    在上传的时候,文件都上传成功了,但是返回的信息里面errcode 404 token 是"".是不是因为我的callbackUrl(随便写的) 写错导致的. 上传golang 版本 ...

  9. redhat赋予普通用户root权限

    方法一:修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉 ## Allows people in group wheel to run all commands%wheel  ...

  10. 微星(MSI)新主板B150M MORTAR U盘装win7的坎坷经历

    新买的微星主板,热心的同事帮忙装好了win10,但是显卡驱动没装好,屏幕都快看瞎了眼,再者,楼主非常不喜欢win10的花哨,所以就装回了win7.下面来说一下我装win7的痛苦经历. 我是用UItra ...