UVA 11853 Paintball ——(dfs+圆交判定)
题意:给出一个1000*1000大小的矩阵,里面有若干圆,表示障碍物,现在要找出从左边到右边的一条通路,输出入口和出口的坐标,如果有多答案,输出y值最大的答案。
分析:从与上面相连的圆开始dfs,每次找与之相交的圆作为dfs的路径,如果能访问到下面,那么左边和右边肯定是不连通的;否则,连通。并且在dfs的时候更新y值最大的答案。
具体见代码:
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
#include <math.h>
using namespace std;
const int N = + ;
const int inf = 2e9;
typedef long long ll;
typedef pair<int,int> pii; int n;
int vis[N];
struct circle
{
int x,y,r;
void read()
{
scanf("%d%d%d",&x,&y,&r);
}
}c[N]; bool can(circle a,circle b)
{
double dx = a.x - b.x;
double dy = a.y - b.y;
double d = sqrt(dx*dx+dy*dy);
return d <= a.r + b.r;
} double ansL = , ansR = ;
void update(int u)
{
if(c[u].x <= c[u].r)
{
double t = sqrt(c[u].r*c[u].r - c[u].x*c[u].x);
double pos = c[u].y - t;
ansL = min(ansL, pos);
}
if(c[u].x + c[u].r >= )
{
double tt = 1000.0 - c[u].x;
double t = sqrt(c[u].r*c[u].r - tt*tt);
double pos = c[u].y - t;
ansR = min(ansR, pos);
}
} bool dfs(int u)
{
vis[u] = ;
if(c[u].y <= c[u].r) return false;
update(u);
for(int i=;i<=n;i++)
{
if(!vis[i] && can(c[u], c[i]))
{
if(!dfs(i)) return false;
}
}
return true;
} void solve()
{
ansL = , ansR = ;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
if(!vis[i] && c[i].y + c[i].r >= )
{
if(!dfs(i))
{
puts("IMPOSSIBLE");
return ;
}
}
}
printf("0.00 %.2f 1000.00 %.2f\n",ansL,ansR);
} int main()
{
while(scanf("%d",&n) == )
{
for(int i=;i<=n;i++) c[i].read();
solve();
}
return ;
}
UVA 11853 Paintball ——(dfs+圆交判定)的更多相关文章
- UVA - 11853 Paintball(dfs)
UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespa ...
- UVA 11853 - Paintball 战场(dfs)
题意:有n个敌人,每个敌人有一个攻击范围,问你是否存在从西边到东边的路径,如果存在,输出入点和出点最靠北的坐标. 把每个敌人看出一个圆,从上往下跑dfs连通,如果到达底部,那么无解.要求出最靠北的坐标 ...
- UVA 11853 Paintball(几何数学+DFS)
https://vjudge.net/problem/UVA-11853 根据题意描述,相当于在一个正方形中有若干个圆形障碍物,问是否能从左边界走到右边界.判断是否有解需要一点创造性的思维:不妨把正方 ...
- Uva - 11853 - Paintball
先判断是否有解,从上到下dfs判断连通性,如果有从顶部到底部连通图,则无解.再判断最北的进出位置,从上边界开始遍历,沿途检查与边界相交的圆.这些圆的左边界的交点中最靠南边的一个就是所有的最北进入位置, ...
- CF 337D 求圆交
题目链接:http://codeforces.com/problemset/problem/337/D 题意:就是一棵树上,有一些点被来自东方的神秘力量影响的,力量影响范围是d,为可能的力量源有几个. ...
- 计算几何(容斥原理,圆交):HDU 5120 Intersection
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The followin ...
- HDU 3264 Open-air shopping malls ——(二分+圆交)
纯粹是为了改进牛吃草里的两圆交模板= =. 代码如下: #include <stdio.h> #include <algorithm> #include <string. ...
- Intersection(HDU5120 + 圆交面积)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面 ...
- HDU 3467 Song of the Siren(圆交)
Problem Description In the unimaginable popular DotA game, a hero Naga Siren, also known as Slithice ...
随机推荐
- java.util.Iterator
public interface Iterator<E>: 对 collection 进行迭代的迭代器. 方法摘要: boolean hasNext() 如果仍有元素可以迭代,则返回 tr ...
- JS 经典代码段总结 start from 2016-08-22
1.for(var i = 0, max = myArray.length; i < max ; i++){ //用myArrayy[i]来做点什么 } 用max存储myArray的长度,防止每 ...
- span设置宽和高当没有内容的时候也可以撑开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HDU 4329 MAP(stringstream的用法)
这个题目有点绕,但是按着他的意思写不难模拟出来.本来是一场学弟们的训练赛,我这个学长在赛场上却WA了四次都没过,三条黑线就一直在我的脑袋上挂着... 赛后开始找原因,后来发现题目看错了,1/R中的R是 ...
- Loadrunner中参数和变量的使用
//字符串复制strcpy(str,"Hello ") ; //字符串连接strcat(str,"World !");lr_message("str: ...
- HttpWatch工具简介及使用技巧(转载)
一 概述: HttpWatch强大的网页数据分析工具.集成在Internet Explorer工具栏.包括网页摘要.Cookies管理.缓存管理.消息头发送/接受.字符查询.POST 数据和目录管理功 ...
- php文件去重复,二维数组筛选
http://www.porter.com/fr/fr/product/648162|Sneakershttp://www.porter.com/fr/fr/product/642115|Bootsh ...
- ContentPlaceHolderID属性
用来对应包含与当前内容关联的 ContentPlaceHolder 的 ID啊 说白了就是去找母版页相应的ContentPlaceHolder ,然后把内容扔进那里面去 <asp:Content ...
- LeetCode OJ 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- set集合容器
set集合容器几条特点 1.它不会重复插入相同键值的元素,而采取忽略处理 2.使用中序遍历算法,检索效率高于vector.deque.list容器,在插入元素时,会自动将元素按键值从小到大排列 3 ...