Earth Hour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)

Total Submission(s): 1516    Accepted Submission(s): 606

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

每一个灯看做一个点,能互相照亮的点连边。从0、1、2三个源点求最短路。然后枚举这3个点到每一个点的最短距离,得到答案。

#include"stdio.h"
#include"string.h"
#include"queue"
#include"vector"
#include"algorithm"
using namespace std;
#define N 205
const int inf=1000000;
int min(int a,int b)
{
return a<b?a:b;
}
struct node
{
int x,y,r;
}p[N];
int g[N][N];
int d[3][N];
int judge(int i,int j) //推断两个灯是否相交
{
int x,y,d,r;
x=p[i].x-p[j].x;
y=p[i].y-p[j].y;
d=x*x+y*y;
r=p[i].r+p[j].r;
if(r*r>=d)
return 1;
return 0;
}
void spfa(int s,int n,int *dis)
{
int i,mark[N];
memset(mark,0,sizeof(mark));
for(i=0;i<n;i++)
dis[i]=inf;
dis[s]=0;
queue<int>q;
q.push(s);
mark[s]=1;
while(!q.empty())
{
s=q.front();
q.pop();
mark[s]=0;
for(i=0;i<n;i++)
{
if(dis[i]>dis[s]+g[s][i])
{
dis[i]=dis[s]+g[s][i];
if(!mark[i])
{
mark[i]=1;
q.push(i);
}
}
}
}
}
int main()
{
int T,i,j,x,y,r,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&x,&y,&r);
p[i].x=x;p[i].y=y;p[i].r=r;
}
for(i=0;i<n;i++)
{
g[i][i]=0;
for(j=0;j<i;j++)
{
if(judge(i,j))
g[i][j]=g[j][i]=1;
else
g[i][j]=g[j][i]=inf;
}
}
spfa(0,n,d[0]);
spfa(1,n,d[1]);
spfa(2,n,d[2]);
int ans=inf;
for(i=0;i<n;i++)
{
ans=min(ans,d[0][i]+d[1][i]+d[2][i]);
}
if(ans<inf)
printf("%d\n",n-ans-1);
else
printf("-1\n");
}
return 0;
}

hdu 3832 Earth Hour (最短路变形)的更多相关文章

  1. HDU 3832 Earth Hour(最短路)

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

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

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

  3. hdu 3832 Earth Hour

    http://acm.hdu.edu.cn/showproblem.php?pid=3832 #include <cstdio> #include <iostream> #in ...

  4. hdu 3832 Earth Hour bfs

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

  5. hdu 6201 transaction (最短路变形——带负权最长路)

    题意: 给定n个城市的货物买卖价格, 然后给定n-1条道路,每条路有不同的路费, 求出从某两个城市买卖一次的最大利润. 利润 = 卖价 - (买价 + 路费) 样例数据, 最近是从第一个点买入, 第4 ...

  6. HDU 6166 Senior Pan (最短路变形)

    题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...

  7. 最短路变形题目 HDU多校7

    Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting of N ports and M sh ...

  8. HDOJ find the safest road 1596【最短路变形】

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)

    做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...

随机推荐

  1. (1)ActivityThread分析

    1. 入口. 曾经一直都说Activity的人口是onCreate方法.事实上android上一个应用的入口,应该是ActivityThread.和普通的java类一样,入口是一个main方法. pu ...

  2. android内存的一点优化

    android手机给应用分配的内存通常是8兆左右,如果处理内存处理不当很容易造成OutOfMemoryError,我们的产品出现最多的错误也是OutOfMemoryError的异常, 在解决这个异常时 ...

  3. 基于visual Studio2013解决C语言竞赛题之1026判断排序

          题目 解决代码及点评 /********************************************************************** ...

  4. SilkTest Q&A 13

    Q121 :我想要测试 windows2003 上的 remote 应用,但是每次都得到如下的错误 我想要测试 windows2003 上的 remote 应用,但是每次都得到如下的错误: " ...

  5. 无限层级且乱序的树形结构数据的整理,利用HashMap降低遍历次数

    我们在展示一个机构树的时候,经常会遇到这种一个问题,查询数据的时候,是从下往上查的,但展示数据的时候,又要从下往上展示. 这时候就要把查询到的数据进行整理从而得到我们想要的结构. 举个样例. ID P ...

  6. 读书与写论文的引导书——leo鉴书60

    我是专科直接考的研究生.在论文写作方面基本能够算是初级.MBA毕业那会儿要写论文,在网上找了不少这方面的书,<论文与治学>是当中之中的一个. 这本那时为应景儿卖的书,成了我之后学习与工作的 ...

  7. js下firstElementChild firstChild 以及childNodes和children方法

    一. <div> <p>123</p> </div> 在上面这段代码中,如果使用以下js代码 var oDiv=document.getElementB ...

  8. Windows Azure入门教学系列 (二):部署第一个Web Role程序

    本文是Windows Azure入门教学的第二篇文章. 在第一篇教学中,我们已经创建了第一个Web Role程序.在这篇教学中,我们将学习如何把该Web Role程序部署到云端. 注意:您需要购买Wi ...

  9. 怎样在Windows和Linux下写相同的代码

    目前,Linux在国内受到了越来越多的业内人士和用户的青睐.相信在不久的将来,在国内为Linux开发 的应用软件将会有很大的增加(这不,金山正在招兵买马移植WPS呢).由于未来将会是Windows和L ...

  10. Eclipse中提高Android SDK Manager下载速度方法

    在Windows-System32-drivers-ect目录下找到hosts文件 打开hosts文件(用记事本打开就可以),在文件以下填上一下内容: 203.208.46.146 www.googl ...