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, &ANTS[I].Y); for(inti =1; I <= N; i++)scanf("%LF%LF", &apple[i].x, &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)