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. python+ubuntu+selenium安装chrome和chromedriver

    请确保selenium已经安装成功,没安装的可以pip install selenium 安装chrome 在终端输入 下载安装包 wget https://dl.google.com/linux/d ...

  2. 使用nvDXT.exe把图片转换成dds图片【转】

    从nvidia官网下载工具包DDS Utilities [https://developer.nvidia.com/legacy-texture-tools] 转换图片格式需要的工具是 nvdxt.e ...

  3. MySQL的id生成策略

    1 自增 CREATE TABLE `test` ( `id` ) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAUL ...

  4. spring自动装配(No qualifying bean )

    No qualifying bean of type [com.wfj.service.cms.main.ChannelMng] found for dependency: expected at l ...

  5. jquery 获取table当前行值

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  6. PL-SQL 包的创建和应用

     PL-SQL 包的创建和应用 ①简单介绍     包是一组相关过程.函数.变量.常量和游标等PL/SQL程序设计元素的组合,它具有面向对象程序设计语言的特点.是对这些PL/SQL 程序设计元素的 ...

  7. Linux Mint (应用软件— 虚拟机:Virtualbox)

    近期想自己折腾一下Linux系统本身.比方Linux裁减或者移植.裁减或者移植Linux是一件麻烦的事情.而且出错后会影响到当前的系统.怎样才干不影响当前机器上的系统呢,于是便想到了虚拟机.在当前系统 ...

  8. Android 完整开源应用大全,完整开源项目

    (Antox)聊天的  (new) (OpenKeychain)OpenPGP在android上的实现  (new) (Flock)提供同步服务 (OpenFlappyBird)以前火爆的坑爹鸟 (F ...

  9. javascript与as3交互

    文章都是发布在github再转到这边的,这边格式可能会乱掉.博客地址:benqy.com 写在前面的废话 公司首页的flash广告,都是由第三方制作的,脚本和flash文件都是由各个广告公司独立制作, ...

  10. SpringSecurity学习二----------实现自定义登录界面

    © 版权声明:本文为博主原创文章,转载请注明出处 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0& ...