Bzoj 2429: [HAOI2006] Smart Monkey (MST)

Source: Internet
Author: User

Water problem, to find MST can be.

--------------------------------------------------------------------------------

#include <bits/stdc++.h>using namespace std;#define SQR (x) ((x) * (x))const int MAXN = 1009;struct Edge {int u, v;double W;BOOL operator < (const edge &e) Const {Return W < E.W;}} E[MAXN * MAXN];struct P {int x, y;inline void Read () {scanf ("%d%d", &x, &y);}} A[MAXN];Double Dist (int x, int y) {return sqrt (SQR (a[x].x-a[y].x) + SQR (a[x].y-a[y].y));} int D[MAXN], N, M, cnt = 0, FA[MAXN];int find (int x) {return x = = Fa[x]? x:fa[x] = Find (fa[x]);}int main () {scanf ("%d", &m);for (int i = 0; i < M; i++) scanf ("%d", D + i);scanf ("%d", &n);for (int i = 0; i < N; i++) a[i]. Read ();for (int i = 0; i < N; i++)For (int j = i + 1; j < N; J + +)e[cnt++] = (edge) {i, J, Dist (i, j)};sort (E, E + CNT);for (int i = 0; i < N; i++) fa[i] = i;double MIN = 0;for (int i = 0; i < cnt; i++) {edge* e = e + i;int u = Find (e->u), V = find (e->v);if (U = v) {Fa[u] = v;min = max (min, e->w);}}int ans = 0;for (int i = 0; i < M; i++) if (D[i] >= MIN) ans++;printf ("%d\n", ans);return 0;}

--------------------------------------------------------------------------------

2429: [HAOI2006] Smart Monkey time limit: ten Sec Memory Limit: MB
Submit: 547 Solved: 376
[Submit] [Status] [Discuss] Description A group of monkeys living in a tropical rainforest, living on the fruit of trees. Yesterday a heavy rain, and now the rain, but the entire rainforest surface is still flooded with water, some of the plant's canopy dew on the surface. Monkeys can not swim, but the ability to jump more than the strong, they are still exposed to the surface of the different canopy on the shuttle to find the fruit like to eat. Now, there are n trees out of the water in this area, assuming that each tree itself is small in diameter and negligible. When we establish a Cartesian coordinate system on this area, the position of each tree is represented by its corresponding coordinates (the coordinates of any two trees are different). The monkeys living in this area had m, and when it rained, they hid in the dense and tall canopy, not swept away by the flood. Because each monkey's age is different, the physique is different, they jump ability is different. Some monkeys jump far from the distance (of course, can also jump to a closer tree), and some monkeys jumping distance is relatively close. These monkeys are very clever, and they can accurately determine whether they will jump to the opposite tree by visual inspection. The "problem" is now known about the number of monkeys and the maximum jumping distance for each monkey, and knowing the coordinates of each tree revealing the surface of the water, your task is to count how many monkeys can feed on all the canopies that are exposed to the surface of the area. Input

Section 1 Acts An integer that represents the number of monkeys M (2<=m<=500);

the 2 behavior M integers, which in turn indicate the maximum jumping distance for monkeys (each integer value is between 1--1000);

Section 3 acts an integer representing the total number of trees N (2<=n<=1000);

Line 4 to n+3 the coordinates of the N tree (the horizontal ordinate is an integer, the range is: -1000--1000).

(separated by a space between integers on the same line)

Output

Includes an integer that indicates the number of monkeys that can forage on all the canopy in the area

Sample Input4
1 2 3 4
6
0 0
1 0
1 2
-1-1
-2 0
2 2
Sample Output3HINT

for 40% data, 2<=n is guaranteed <=100,1<=m<=100


for all data, 2<=n <= is guaranteed 1000,1<=m=500



Source

Day2

Bzoj 2429: [HAOI2006] Smart Monkey (MST)

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.