Earth Hour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1970    Accepted Submission(s): 781

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.
 
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.
 

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.
 

Sample Input

3
5
1 1 1
1 4 1
4 1 1
2 2 1
3 3 1
7
1 1 1
4 1 1
2 4 1
1 3 1
3 1 1
3 3 1
4 3 1
6
1 1 1
5 1 1
5 5 1
3 1 2
5 3 2
3 3 1

Sample Output

-1
2
1
 
T 个数据,2D 平面内 n (>=3)个点,再 n 行 x , y , r 表示(x,y)位置的灯照射半径为 r ,要 1 ,2 , 3 点,连通并都照亮,问最多可以关掉几盏灯
//这道题有点难,先要把数据抽象成一个图,如果两两可以连通则设距离为 1 ,不能连通设为 INF 然后分别求1,2,3,这三个点到其余点的最短路径,3个结果都加起来后,那个最小值的点理解为从这点出发,连通1,2,3三个点最短路径,也可以说是最少需要开几盏灯(这个值不会有重复计算的灯),n-之 就是答案
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 205
#define INF 100000000 struct Node
{
int x,y;
int r;
}node[MAXN];
int G[MAXN][MAXN]; //连通关系
int dis[MAXN];
int vis[MAXN];
int res[MAXN]; void dij(int n,int p)
{
for (int i=;i<=n;i++)
{
dis[i]=G[p][i];
vis[i]=;
}
dis[p]=;
vis[p]=; for (int i=;i<n;i++)
{
int mp,mmm=INF;
for (int j=;j<=n;j++)
if (!vis[j]&&dis[j]<mmm)
{
mmm=dis[j];
mp=j;
}
if (mmm==INF)
break;
vis[mp]=;
for (int j=;j<=n;j++)
{
if (!vis[j]&&dis[mp]+G[mp][j]<dis[j])
dis[j]=dis[mp]+G[mp][j];
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for (int i=;i<=n;i++)
{
int x,y,r;
scanf("%d%d%d",&x,&y,&r);
node[i]=(Node){x,y,r};
for (int j=;j<=i;j++)
{
double dist = sqrt((node[j].x-x)*(node[j].x-x)*1.0+(node[j].y-y)*(node[j].y-y)*1.0);
if (dist-(node[j].r+r)<1e-)
G[i][j]=G[j][i]=;
else
G[i][j]=G[j][i]=INF;
}
}
memset(res,,sizeof(res));
dij(n,);
for (int i=;i<=n;i++)
res[i]+=dis[i];
dij(n,);
for (int i=;i<=n;i++)
res[i]+=dis[i];
dij(n,);
for (int i=;i<=n;i++)
res[i]=n-(res[i]+dis[i]+);
int ans=-;
for (int i=;i<=n;i++)
ans=max(ans,res[i]);
printf("%d\n",ans);
}
return ;
}

Earth Hour(最短路)的更多相关文章

  1. hdu 3832 Earth Hour (最短路变形)

    Earth Hour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Tota ...

  2. HDU 3832 Earth Hour(最短路)

    题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...

  3. hdu 3832 Earth Hour(最短路变形)

    Earth Hour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  4. 【转】最短路&差分约束题集

    转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...

  5. Codeforces Round #406 (Div. 1) B. Legacy 线段树建图跑最短路

    B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...

  6. Codeforces 787D. Legacy 线段树建模+最短路

    D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  7. Codeforces787D(SummerTrainingDay06-D 线段树+最短路)

    D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  8. CF 787D Legacy(线段树思想构图+最短路)

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  9. 转载 - 最短路&差分约束题集

    出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548    A strange lift基础最短路(或bfs)★ ...

随机推荐

  1. 了解Linux实时内核

    了解Xenomai过程中,对现阶段的RTOS进行总结如下: 把现阶段的RTOS分成两个阵营: 非Linux阵营:VxWorks,RTEMS Linux阵营 :RT-linux,Preempt-rt,W ...

  2. asp.net购物车,订单以及模拟支付宝支付(四)---模拟支付宝支付

    下完订单之后到支付宝付款,成功之后再返回来修改订单状态.由于只是测试,所以就没有真正的连接到支付宝,用的是一个模拟支付宝的程序 下载地址:支付宝模拟程序 这是一个vs2010的项目,本来网上找了一个模 ...

  3. 搭建Drupal-8.5.3

    环境说明 系统版本    CentOS 6.9 x86_64 软件版本    yum安装nginx 1.10.2 yum安装php 7.2.6(当前的最新版本) yum安装mysql 5.5.60 d ...

  4. Android NDK生成共享库和静态库

    Date: 2014-03-14 Title: Compile Android Native Binary And Library Published: true Type: post Tags: A ...

  5. 系统封装 ES3使用方法

    1 什么是系统封装? 系统封装,说简单就是把系统制作成镜像的方法制作Ghost镜像文件,用在系统安装上面.系统封装,不同于系统的正常安装.最本质的区别在于 系统封装 是将一个完整的系统以拷贝的形式打包 ...

  6. hbuilder - wap to app

    官方文档: http://www.dcloud.io/wap2app.html 新建Wap2App,示例网址:www.baidu.com 随后,我们可以在 最后,我们可以 打包完成以后,下载即可

  7. SQLite升级数据库:

    SQLiteOpenHelper子类关键代码: SQLite升级数据库: SQLiteOpenHelper子类关键代码: public class MyDataHelper extends SQLit ...

  8. TCO'10 Online Round 3 1000pt

    题目大意: 密码串由小写字母.大写字母和数字组成,要求求出小写字母个数不少于L个.大写字母个数不少于U个.数字个数不少于D个的长度为N密码串的种数. 答案对 1000000009 取模 解题思路: 自 ...

  9. 【Excle数据透视表】如何快速选定数据透视表的汇总行并添加绿色底纹

    数据透视表创建好之后,如何批量将汇总行的底色修改为绿色呢?目标效果图如下: 解决方案 "启用选定内容"选取所有汇总行 单击任意汇总字段(如:北京 汇总)→选择→启用选定内容→开始→ ...

  10. 使用Gitolite搭建Gitserver

    Gitolite是一款Perl语言开发的Git服务管理工具.通过公钥对用户进行认证.并可以通过配置文件对些操作进行基于分支和路径的精细控制. Gitolite採用的是SSH协议而且使用SSH公钥认证. ...