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. Linux7个runlevel

    Linux系统有7个运行级别(runlevel) 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆 运行级别 ...

  2. Poj 4227 反正切函数的应用

    Description 反正切函数可展开成无穷级数,有例如以下公式 (当中0 <= x <= 1) 公式(1) 使用反正切函数计算PI是一种经常使用的方法.比如,最简单的计算PI的方法: ...

  3. selenium 的页面对象模型Page Object

    页面对象模型page object model是selenium中的一种脚本设计模式,它能将页面元素封装起来,与业务操作分隔开, 在页面变化改变时,无需去修改业务逻辑代码,提高脚本维护的效率. 1.p ...

  4. Win7 Visual Studio 2008如何注册

    默认是90天试用   在控制面板中卸载程序,然后找到VS2008,点击卸载/更改   到这一步就不要动了   去下载并运行CrackVS2008ForWindows7,然后点击右上角的Bug微软,弹出 ...

  5. Efficiently traversing InnoDB B+Trees with the page directory--slot

    Efficientlytraversing InnoDB B+Trees with the page directory 1.the purpose of the page directory As ...

  6. Tomcat、Weblogic、JBoss、GlassFish、Resin、Websphere弱口令及拿webshell方法总结 [复制链接]

    1.java应用服务器    Java应用服务器主要为应用程序提供运行环境,为组件提供服务.Java 的应用服务器很多,从功能上分为两类:JSP 服务器和 Java EE 服务器.1.1  常见的Se ...

  7. Android学习(十五) 系统服务

    一.常用系统服务 后台Service在系统启动时被SystemService开启 1.MountService:监听是否有SD卡安装和移除. 2.ClipboardService:提供剪切板功能. 3 ...

  8. Linux经常使用命令(八) - touch

    linux的touch命令不经常使用, 一般用来改动文件时间戳, 或者新建一个不存在的文件. 1. 命令格式: touch [选项]  文件 2. 命令參数: -a    仅仅更改存取时间. -c   ...

  9. selenium从入门到应用 - 1,环境准备(Java+TestNG+Maven+Selenium)

    本系列所有代码 https://github.com/zhangting85/simpleWebtest 本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境的 ...

  10. Android Shader 颜色、图像渲染 paint.setXfermode

    Shader Shader是一个基类,表示在绘制期间颜色的水平跨度 它的子类被嵌入在Paint中使用,调用paint.setShader(shader). 除Bitmap外的其他对象,使用该Paint ...