Ultraviolet A 11853-paintball (DFS)

Source: Internet
Author: User
Ultraviolet A 11853-paintball

Question Link

It is to give some circles and determine whether they can go from the left to the right without passing through these circles. If you can ask the start and end positions to the north as far as possible, the output position

Idea: Every time I find a circle DFS that exceeds the upper boundary, if it can reach the lower boundary, it will be unable to reach the partition. If it is left and right boundary, I need to update the answer value.

Code:

#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;}


Ultraviolet A 11853-paintball (DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.