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的值的个数.现在要求寻找最小步数,显然要减去一 ...
随机推荐
- URAL 2027 2028 两个有趣的题
这两个题,讲的是有一种奇怪的语言,代码是一种二维的矩阵. 前一个题,是根据所给的要求,写一个简单的解释器. 后一个题,是用那种语言写一个简单的小程序. 挺有意思的,所以在这里纪念一下.顺便那个语言的原 ...
- CodeForces - 552E Vanya and Brackets
Vanya and Brackets Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u ...
- java用jxl实现导出execl表格
//先将需要导出的数据放到list中 //然后将list中的数据放到execl表中 @RequestMapping(params="exportExecl") public Str ...
- CSS中的相关概念
CSS的几个概念: 包括块:一个元素的"布局上下文".对于正常的HTML文本流中的一个元素,包括块由近期的块级祖先框.表单元格或行内块祖先框的内容边界(content edge)构 ...
- html-上左右布局方式---ShinePans
文件包括 main.html top.html left.html childhood.html moonsong.html herethesea.html 主要布局效果: 代码: main ...
- 【大话QT之十六】使用ctkPluginFramework插件系统构建项目实战
"使用ctkPluginFramework插件系统构建项目实战",这篇文章是写博客以来最纠结的一篇文章. 倒不是由于技术都多么困难,而是想去描写叙述一个项目架构採用ctkPlugi ...
- server用JDBC对mysql数据库进行操作
1:获取数据库连接 Connection connection=getConnection(); 2:准备SQL语句 3:调用Connection的creatStatement()方法获取Statem ...
- nyoj--42--一笔画问题(并查集)
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. ...
- linux下修改完profile文件的环境变量后如何立即生效
方法1: 让/etc/profile文件修改后立即生效 ,可以使用如下命令: # . /etc/profile 注意: . 和 /etc/profile 有空格 方法2: 让/etc/profile文 ...
- POJ 2478 线性递推欧拉函数
题意: 求sigma phi(n) 思路: 线性递推欧拉函数 (维护前缀和) //By SiriusRen #include <cstdio> using namespace std; # ...