Title Address: HDU 3832
I can't give a proof of this method of the problem.
When I came out with this idea, I was thinking that if I wanted to cover the fewest points, I would try to use them over and over again, and then have two of them connected by a point indirectly, which would make the most of those points.
And then wrote it once, always WA. And then at noon, when I went to bed, it occurred to me that there was a situation that was incorrect. That is, there is a point as the middle point, with three points connected to the situation, such a situation, although also meet. But there will be repeated side ...
But the opposite is true. The more you repeat, the better.
。
Then make full use of these points. So how do we find this point? Well, then just enumerate them. However, it is very obvious that it is not scientific to enumerate every point to find the shortest possible time.
Anyway, just use the shortest distance to the three points, then only the three points to be asked for once, then the other point to the three points of the shortest way is to find out.
Then enumerate the sum of the distances from all points to three points to find the smallest one. Subtracting the minimum value by n is the maximum value that needs to be closed.
The code is as follows:
#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < math.h> #include <ctype.h> #include <queue> #include <map> #include <algorithm>using namespace Std;const int Inf=0x3f3f3f3f;int head[300], cnt, vis[300];int d[3][301];struct node1{int x, y, R;} dian[1000 000];struct node{int U, V, W, Next,} edge[1000000];void Add (int u, int v, int w) {edge[cnt].v=v; Edge[cnt].w=w; Edge[cnt].next=head[u]; head[u]=cnt++;} void Spfa (int source, int x) {memset (d[x],inf,sizeof (d[x])); memset (vis,0,sizeof (VIS)); d[x][source]=0; deque<int>q; Q.push_back (source); while (!q.empty ()) {int U=q.front (); Q.pop_front (); vis[u]=0; for (int i=head[u]; i!=-1; i=edge[i].next) {int v=edge[i].v; if (D[X][V]>D[X][U]+EDGE[I].W) {D[X][V]=D[X][U]+EDGE[I].W; if (!vis[v]) { Vis[v]=1; if (!q.empty () &&d[x][v]<d[x][q.front ()]) {Q.push_front (v); } else {q.push_back (v); }}}}}}int main () {int T, n, x, Y, R, ans, I, J, Min1; Double Z; scanf ("%d", &t); while (t--) {scanf ("%d", &n); memset (head,-1,sizeof (head)); cnt=0; for (I=1; i<=n; i++) {scanf ("%d%d%d", &DIAN[I].X,&DIAN[I].Y,&DIAN[I].R); } for (I=1, i<=n; i++) {for (j=1; j<i; J + +) {z=sqrt (Dian[i].x-di an[j].x) *1.0* (dian[i].x-dian[j].x) + (DIAN[I].Y-DIAN[J].Y) *1.0* (DIAN[I].Y-DIAN[J].Y)); if (Z<=DIAN[I].R+DIAN[J].R) {Add (i,j,1); Add (j,i,1); }}} SPFA (1,0); SPFA (2,1); SPFA (3,2); Min1=inf; if (d[0][2]==inf| | D[0][3]==inf) {printf (" -1\n"); Continue; } for (i=1;i<=n;i++) {if (D[0][i]!=inf&&d[1][i]!=inf&&d[2][i]!=inf) {if (min1>d[0][i]+d[1][i]+d[2][i]+1) {min1=d[0][i]+d[1][i]+d[2][i]+1; }}} printf ("%d\n", n-min1); } return 0;}
HDU 3832 Earth Hour (Shortest way)