HDOJ-4562/sishanju semi-finals 2 guardian Athena

Source: Internet
Author: User

WA was a mess during the competition ~~ Reason !.. Careless reading !! The output of the previous question is Case #1: 0, and this question is Case 1: 1... the same set of questions...

The idea is simple .. which can generate defense results .. it is nothing more than a circle that can enclose Athena or a monster .. while while a circle simultaneously holds Athena and the monster .. there is no defense effect ..

Consider the problem that N circles hold one point and can obtain the maximum number of circles from each other .. solve with dp .. in the dp sequence, the circle radius ranges from small to large (obviously, the radius of a circle must be larger than that of another circle )...

Respectively, the dp value of Athena dp [0] [] and the dp value of the monster dp [1] []. find the number of the largest circles that do not conflict with each other... is the answer ..

Program:

# Include <iostream> # include <stdio. h> # include <cmath> # include <string. h> # include <algorithm> # include <stack> # include <queue> # include <map> # include <set> # define pi acos (-1.0) # define ll long # define oo 1000000000 # define MAXN 1005 using namespace std; struct node {int x, y, r;} a [MAXN]; int n, x, y, sum [2] [MAXN]; bool cmp (node a, node B) {return. r <B. r;} bool OK (node a, node B) // judge whether two circles do not intersection/cut {int d, r1, r2; d = (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y); r1 =. r-b.r; r2 =. r + B. r; if (r1 * r1 <= d & d <= r2 * r2) return false; return true;} int main () {int T, t, I, j, ans; scanf ("% d", & T); for (t = 1; t <= T; t ++) {scanf ("% d ", & n, & x, & y); for (I = 1; I <= n; I ++) scanf ("% d ", & a [I]. x, & a [I]. y, & a [I]. r); sort (a + 1, a + 1 + n, cmp); ans = 0; memset (sum, 0, sizeof (sum); for (I = 1; I <= n; I ++) {if (a [I]. x * a [I]. x + a [I]. y * a [I]. y> = a [I]. r * a [I]. r | (a [I]. x-x) * (a [I]. x-x) + (a [I]. y-y) * (a [I]. y-y) <= a [I]. r * a [I]. r) // find the continue that contains Athena but does not support monsters. for (j = 1; j <I; j ++) if (sum [0] [I] <sum [0] [j] & OK (a [I], a [j]) sum [0] [I] = sum [0] [j]; sum [0] [I] ++; ans = max (ans, sum [0] [I]) ;}for (I = 1; I <= n; I ++) {if (a [I]. x * a [I]. x + a [I]. y * a [I]. y <= a [I]. r * a [I]. r | (a [I]. x-x) * (a [I]. x-x) + (a [I]. y-y) * (a [I]. y-y)> = a [I]. r * a [I]. r) // find out the continue that contains the monsters but does not support Athena; for (j = 1; j <I; j ++) if (sum [1] [I] <sum [1] [j] & OK (a [I], a [j]) sum [1] [I] = sum [1] [j]; sum [1] [j] ++; ans = max (ans, sum [1] [I]) ;}for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) if (ans <sum [0] [I] + sum [1] [j] & OK (a [I], a [j]) ans = sum [0] [I] + sum [1] [j]; // merge two results: printf ("Case % d: % d \ n", t, ans);} return 0 ;}

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.