HDU 1875 smooth engineering recontinued

Source: Internet
Author: User

HDU 1875 smooth engineering recontinued
B-Minimum Spanning Tree 2
Time Limit: 1000 ms memory limit: 32768kb 64bit Io format: % i64d & % i64u
Submit

Status
Description

After the study team rprush had a full understanding of the situation of the Island Lake, he decided to build an upper bridge between qualified small islands,
That is, the distance between two small islands cannot be less than 10 meters or more than 1000 meters.
Of course, in order to save money, we only need to implement a road connection between any two small islands.
The price of the middle bridge is 100 yuan/meter.

Input
The input includes multiple groups of data.
The input includes an integer T (t <= 200), which indicates that there is a T group of data.
Each group of data is first an integer c (C <= 100), representing the number of small islands, followed by the coordinates of group C,
Represents the coordinates of each small island. These coordinates are integers 0 <= X, Y <= 1000.

Output
Output a row of input data in each group, which indicates the minimum cost of the bridge. The result is retained with a decimal number.

If the project cannot be implemented to achieve smooth operation, output "Oh !".

Sample Input
2
2
10 10
20 20
3
1 1
2 2
1000 1000

Sample output
1414.2
Oh!

 

or the minimum spanning tree should be optimized by 200 + Ms.

# Include <stdio. h> # include <string. h> # include <math. h> # include <iostream> # include <algorithm> # include <queue> # include <stack> # define MEM (a, B) memset (A, B, sizeof (A) # define ll _ int64 # define maxn 1000 # define INF 0x7ffffff # define lson L, M, RT <1 # define rson m + 1, R, RT <1 | 1 using namespace STD; struct point {Double X, Y ;}; struct road {int F, T; double W ;}; point P [250]; road R [50000]; int fat [250]; int sum, CNT, N; double Ans; int CMP (Road A, road B) {return A. W <B. W;} int find (int A) {// return a = fat [a]? A: Find (fat [a]); if (! = Fat [a]) {fat [a] = find (fat [a]);} return fat [a];} void Kruskal () {for (INT I = 1; I <= N; I ++) fat [I] = I; for (INT I = 1; I <CNT; I ++) {int x = find (R [I]. f); int y = find (R [I]. t); If (X! = Y & R [I]. w> = 10 & R [I]. W <= 1000) {sum ++; ans + = R [I]. w; fat [y] = x ;}if (sum = N) {ans * = 100; printf ("%. 1f \ n ", ANS);} else cout <" Oh! \ N ";}int main () {int I, j, T; CIN >>t; while (t --) {scanf (" % d ", & N ); sum = 1; ans = 0; for (I = 1; I <= N; I ++) {scanf ("% lf", & P [I]. x, & P [I]. y);} CNT = 1; for (I = 1; I <n; I ++) {for (j = I + 1; j <= N; j ++) {R [CNT]. F = I; R [CNT]. T = J; R [CNT]. W = SQRT (FABS (POW (P [I]. x-P [J]. x, 2) + POW (P [I]. y-P [J]. y, 2); CNT ++ ;}// cout <CNT <Endl; sort (R + 1, R + CNT, CMP ); kruskal ();} 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.