UVA 11853 - Paintball(dfs)
来源:互联网 发布:武汉富士康2018java 编辑:程序博客网 时间:2024/05/15 00:36
UVA 11853 - Paintball
题目链接
题意:就是给定一些圆,判断能否不经过这些圆从左边走到右边,如果可以要求起始和终止位置尽量往北,输出位置
思路:每次找一个超出上边界的圆dfs,如果能到下边界,就是隔断了肯定到达不了,如果隔断左右边界,就要更新答案的值
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>using namespace std;const int N = 1005;int n, vis[N];struct Circle {int x, y, r;void read() {scanf("%d%d%d", &x, &y, &r);}} c[N];double ans1, ans2;bool can(Circle a, Circle b) {int dx = a.x - b.x;int dy = a.y - b.y;return dx * dx + dy * dy - (a.r + b.r) * (a.r + b.r) <= 0;}bool dfs(int u) {vis[u] = 1;if (c[u].y - c[u].r <= 0) return false;if (c[u].x - c[u].r <= 0) ans1 = min(ans1, c[u].y - sqrt(c[u].r * c[u].r - c[u].x * c[u].x));if (1000 - c[u].x - c[u].r <= 0) ans2 = min(ans2, c[u].y - sqrt(c[u].r * c[u].r - (1000 - c[u].x) * (1000 - c[u].x)));for (int i = 0; i < n; i++) {if (vis[i]) continue;if (can(c[u], c[i]))if (!dfs(i)) return false;}return true;}void solve() {ans1 = ans2 = 1000;for (int i = 0; i < n; i++) {if (!vis[i] && c[i].y + c[i].r >= 1000)if (!dfs(i)) {printf("IMPOSSIBLE\n");return;}}printf("0.00 %.2lf 1000.00 %.2lf\n", ans1, ans2);}int main() {while (~scanf("%d", &n)) {for (int i = 0; i < n; i++) {c[i].read();vis[i] = 0;}solve();}return 0;}
1 0
- UVA 11853 - Paintball(dfs)
- UVa 11853 - Paintball(DFS)
- [UVA 11853]Paintball[DFS]
- UVa 11853 - Paintball <图论+DFS>
- uva 11853 Paintball dfs找连通块
- Uva - 11853 - Paintball
- UVa 11853 PaintBall
- uva 11853 Paintball
- UVA 11853 Paintball
- Paintball(dfs判断连通)
- uva 11853 paintball(好题)——yhx
- uva 11853 paintball(好题)——yhx
- 例题6-22 战场(Paintball, UVa 11853)
- Paintball UVA
- 例题6-22 UVA 11853 Paintball 战场
- DFS--uva11853 Paintball
- 11853 - Paintball
- UVA Transportation (DFS)
- PushbackInputStream简介及用法
- UML建模之时序图(Sequence Diagram)
- CentOS---网络配置详解
- Cocos2d-x之 CCObject
- __cdecl __stdcall区别
- UVA 11853 - Paintball(dfs)
- 乐元素面试
- Oracle -- Coalesce
- C++ 类非静态成员函数作为线程入口函数实现
- ZOJ Problem Set - 2027
- dbca建库不识别ASM存储
- c++类模板实例化验证
- nyoj15括号匹配(二)
- POJ Gold Balanced Lineup(3274)-神Hash