UVALive-4043 Ants (km bare title)

Source: Internet
Author: User

The main idea: give the coordinates of n ants and n trees, ask how to perfect match, so that the ants to the tree of the connection will not intersect

Problem solving ideas: km naked problem, but very depressed AH
Do not open the root, with a long long unexpectedly can not, very no language ah, the distance is only 800 million AH
Then with a double code, he changed it to a long long, WA
Then with double A's code, do not open root, and WA, this question really what the hell is the pit

#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace STD;#define N#define INF 1e20#define ESP 1e-10structnode{Doublex, y;} Ants[n], apple[n];DoubleW[n][n];DoubleLx[n], ly[n];intLeft[n], N;BOOLS[n], t[n];voidInit () { for(inti =1; I <= N; i++)scanf("%LF%LF", &ants[i].x, &AMP;ANTS[I].Y); for(inti =1; I <= N; i++)scanf("%LF%LF", &apple[i].x, &AMP;APPLE[I].Y);Doublex1, x2, y1, y2; for(inti =1; I <= N;         i++) {x1 = apple[i].x; y1 = apple[i].y; for(intj =1; J <= N;            J + +) {x2 = ants[j].x;            y2 = ants[j].y; W[I][J] =-sqrt((X1-X2) * (X1-X2) + (y1-y2) * (Y1-y2)); }    }}BOOLMatchintu) {S[u] =true; for(intj =1; J <= N; J + +) {if(fabs(Lx[u] + ly[j]-w[u][j]) < ESP &&! T[j]) {T[j] =true;if(!left[j] | | match (LEFT[J)) {Left[j] = u;return true; }        }    }return false;}voidUpdate () {DoubleMin = INF; for(inti =1; I <= N; i++)if(S[i]) for(intj =1; J <= N; J + +)if(! T[j] min = min (Lx[i] + ly[j]-w[i][j], min); for(inti =1; I <= N; i++) {if(S[i]) lx[i]-= Min;if(T[i]) ly[i] + = Min; }}voidEK () { for(inti =1; I <= N; i++) {Left[i] = ly[i] =0; Lx[i] =-inf; for(intj =1; J <= N;    J + +) Lx[i] = max (Lx[i], w[i][j]); } for(inti =1; I <= N; i++) { while(1) { for(intj =1; J <= N; J + +) S[j] = t[j] =0;if(Match (i)) Break;ElseUpdate (); }    }}intMain () {intCNT =0; while(scanf("%d", &n)! = EOF) {if(cnt++)printf("\ n");        Init (); EK (); for(inti =1; I <= N; i++)printf("%d\n", Left[i]); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVALive-4043 Ants (km bare title)

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.