HDU 3832 Earth Hour (最短路)
来源:互联网 发布:流行朋克知乎 编辑:程序博客网 时间:2024/05/16 04:56
Problem Description
Earth Hour is an annual international event created by the WWF (World Wide Fund for Nature/World Wildlife Fund), held on the last Saturday of March, that asks households and businesses to turn off their non-essential lights and electrical appliances for one hour to raise awareness towards the need to take action on climate change.
To respond to the event of this year, the manager of Hunan University campus decides to turn off some street lights at night. Each street light can be viewed as a point in a plane, which casts flash in a circular area with certain radius.
What's more, if two illuminated circles share one intersection or a point, they can be regarded as connected.
Now the manager wants to turn off as many lights as possible, guaranteeing that the illuminated area of the library, the study room and the dormitory are still connected(directly or indirectly). So, at least the lights in these three places will not be turned off.
To respond to the event of this year, the manager of Hunan University campus decides to turn off some street lights at night. Each street light can be viewed as a point in a plane, which casts flash in a circular area with certain radius.
What's more, if two illuminated circles share one intersection or a point, they can be regarded as connected.
Now the manager wants to turn off as many lights as possible, guaranteeing that the illuminated area of the library, the study room and the dormitory are still connected(directly or indirectly). So, at least the lights in these three places will not be turned off.
Input
The first line contains a single integer T, which tells you there are T cases followed.
In each case:
The first line is an integer N( 3<=N<=200 ), means there are N street lights at total.
Then there are N lines: each line contain 3 integers, X,Y,R,( 1<=X,Y,R<=1000 ), means the light in position(X,Y) can illuminate a circle area with the radius of R. Note that the 1st of the N lines is corresponding to the library, the 2nd line is corresponding to the study room, and the 3rd line is corresponding to the dorm.
In each case:
The first line is an integer N( 3<=N<=200 ), means there are N street lights at total.
Then there are N lines: each line contain 3 integers, X,Y,R,( 1<=X,Y,R<=1000 ), means the light in position(X,Y) can illuminate a circle area with the radius of R. Note that the 1st of the N lines is corresponding to the library, the 2nd line is corresponding to the study room, and the 3rd line is corresponding to the dorm.
Output
One case per line, output the maximal number of lights that can be turned off.
Note that if none of the lights is turned off and the three places are still not connected. Just output -1.
Note that if none of the lights is turned off and the three places are still not connected. Just output -1.
Sample Input
351 1 11 4 14 1 12 2 13 3 171 1 14 1 12 4 11 3 13 1 13 3 14 3 161 1 15 1 15 5 13 1 25 3 23 3 1
Sample Output
-121
求出每条可能存在的边权值赋为1,分别以1,2,3为起点进行Dij,然后枚举每个点,以该点作为桥梁 联通1,2,3,当然这些联通的点经过的点越少越好,那么求出min(d1[i]+d2[i]+d3[i]) ,即为总联通的点数减1,再用n-1减去这个值就为可去掉的最大的值。
#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>#include <stack>#define lson o<<1, l, m#define rson o<<1|1, m+1, rusing namespace std;typedef long long LL;const int maxn = 305;const int MAX = 0x3f3f3f3f;const int mod = 1000000007;int t, n, g[maxn][maxn];int d[4][maxn], vis[maxn];struct C1 { int x, y, r;}in[maxn];int getdis(int x1, int y1, int x2, int y2) { return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ;}void In() { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d%d%d", &in[i].x, &in[i].y, &in[i].r); memset(g, MAX, sizeof(g)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { int tmp = getdis(in[i].x, in[i].y, in[j].x, in[j].y); if( tmp <= (in[i].r + in[j].r)*(in[i].r + in[j].r) ) g[i][j] = 1; }}void DIJ(int st) { memset(d[st], MAX, sizeof(d[st])); memset(vis, 0, sizeof(vis)); d[st][st] = 0; for(int i = 0; i < n; i++) { int tmp = MAX, pos; for(int j = 0; j < n; j++) if(vis[j] == 0 && d[st][j] < tmp) { tmp = d[st][j]; pos = j; } vis[pos] = 1; for(int j = 0; j < n; j++) if(!vis[j] && d[st][j] > d[st][pos]+g[pos][j]) d[st][j] = d[st][pos]+g[pos][j]; }}int main(){ scanf("%d", &t); while(t--) { In(); DIJ(0); DIJ(1); DIJ(2); int ans = MAX; for(int i = 0; i < n; i++){ if(d[0][i] != MAX && d[1][i] != MAX && d[2][i] != MAX) // 如果没有这句话,三个数加起来可能会爆int ans = min(ans, d[0][i] + d[1][i] + d[2][i]); } if(ans == MAX) printf("-1\n"); else printf("%d\n", n-1-ans); } return 0;}
0 0
- HDU 3832 Earth Hour(最短路)
- HDU 3832 Earth Hour (最短路)
- HDU-3832 Earth Hour 最短路
- hdu 3832Earth Hour 最短路spfa
- hdu 3832 Earth Hour (最短路变形)
- hdoj 3832 Earth Hour(最短路)
- HDU 3832 Earth Hour 最短路(三点联系,有一个公共区)
- [最短路] hud 3832 Earth Hour
- hdoj 3832 Earth Hour 【最短路&&SPFA】
- HDU 3832 Earth Hour
- hdu 3832 Earth Hour
- hdu 3832 Earth Hour
- HDU 3832 Earth Hour
- HDU-3832-Earth Hour
- hdu3832-Earth Hour-最短路dij
- HDU/HDOJ 3832 Earth Hour
- hdu 3832 Earth Hour(斯坦纳树)
- 复习--F - Earth Hour(最短路,连接1 2 3个点)
- Spring Aop实例
- 模板方法模式
- awk学习笔记
- 黑马程序员——网络编程
- uva11255 - Necklace 项链旋转翻转 置换
- HDU 3832 Earth Hour (最短路)
- C++ Primer 【第四版】第九章 顺序容器
- HDU 2298-Run(二分)
- window8.1 metro应用开发 之helloworld
- 黑马程序员--------------面向对象
- linux视频学习网站
- Android的Intent和IntentFilter应用说明一例
- 写给曾经的自己现在的自己和未来的自己
- maven之生命周期和插件