Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5934
Test instructions: There are n bombs, each bomb placed in (x, y) This position, it can blast the range is the radius of the circle of R, the cost of the manual detonation of the Bomb is C, when a bomb exploded,
All the bombs in the area of its explosion will be detonated by it, so what is the minimum cost to detonate all the bombs?
Set up a one-way map, and then the point of contraction, each point of the weight of the link is the right value of the small one, and then find all the points into the 0, and add up their weights is the result;
#include <stdio.h>#include<string.h>#include<algorithm>#include<vector>using namespacestd;#defineMet (A, b) memset (A, B, sizeof (a))typedefLong LongLL;Const intN =1100;Const intINF =0x3f3f3f3f;Const DoubleEPS = 1e-Ten;structnode{LL x, Y, R;} A[n];intN, W[n], min[n], dfn[n], low[n], vis[n];intBlock[n], Nblock, Stack[n], Top, time, Degree[n];vector<int>G[n];voidInit () { for(intI=0; i<=n; i++) g[i].clear (); Met (Min, INF);///Min[i] Represents the minimum cost of each unicom block after the contraction point;Met (degree,0);///record the degree of indentation after the pinch;Met (DFN,0); Met (Low,0); Met (Stack,0); Met (Vis,0); Met (Block,0); Nblock= Top = time =0;}voidTajar (intu) {Low[u]= Dfn[u] = + +Time ; Stack[top++] =u; Vis[u]=1; intv; for(intI=0, Len=g[u].size (); i<len; i++) {v=G[u][i]; if(!Dfn[v]) {Tajar (v); Low[u]=min (Low[u], low[v]); } Else if(Vis[v]) Low[u]=min (Low[u], dfn[v]); } if(Low[u] = =Dfn[u]) { ++Nblock; Do{v= stack[--Top]; BLOCK[V]=Nblock; VIS[V]=0; } while(u!=v); }}intMain () {intT, T =1; scanf ("%d", &T); while(T--) {scanf ("%d", &N); Init (); for(intI=1; i<=n; i++) scanf ("%i64d%i64d%i64d%d", &a[i].x, &a[i].y, &A[I].R, &W[i]); for(intI=1; i<=n; i++)///Building Map { for(intj=1; j<=n; J + +) {LL d= (a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (a[i].y-a[j].y); if(A[I].R*A[I].R >=d) G[i].push_back (j); } } for(intI=1; i<=n; i++)///shrinking point; { if(!Dfn[i]) Tajar (i); } for(intI=1; i<=n; i++) { for(intj=0, Len=g[i].size (); j<len; J + +) { intx =G[i][j]; intU = block[i], V =Block[x]; if(U! = V) degree[v] + +; Min[u]=min (Min[u], w[i]); MIN[V]=min (Min[v], w[x]); } } intAns =0; for(intI=1; i<=nblock; i++) { if(Degree[i] = =0) ans+=Min[i]; } printf ("Case #%d:%d\n", t++, ans); } return 0;}
View Code
Bomb---hdu5934 (connected graph pinch point)