Earth Hour

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

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
 
 

题意:N个路灯,1,2,3,分别表示图书馆,宿舍,自习室,尽可能关掉灯使得3个区域连在一起还是亮着(每个点给定圆点和半径,两圆相切或相交则为两区域连在一起)。

要使三个区域连在一起并且亮着,那么三个区域之间必须要有灯,或者三个区域本来就连着。尽可能的关掉灯,就可以在所有的灯中找到一个灯,它到三个灯的路径最短(连着的灯最少)。

附上代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f
#define N 205
#define M 1005
using namespace std;
int n,m;
struct point
{
int x,y,r;
} p[N];
int map[M][M],dis[][M];
bool vis[M]; void spfa(int s)
{
for(int i=;i<=n;i++)
{
dis[s][i]=INF;
vis[i]=false;
}
queue<int>q;
q.push(s);
dis[s][s]=;
vis[s]=true;
while(!q.empty())
{
int u=q.front();
q.pop();
vis[u]=false;
for(int i=; i<=n; i++)
{
if(dis[s][i]>dis[s][u]+map[u][i])
{
dis[s][i]=dis[s][u]+map[u][i];
if(!vis[i])
{
vis[i]=true;
q.push(i);
}
}
}
}
} double dist(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} int main()
{
int T,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=; i<=n; i++)
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].r);
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
double d=dist(p[i],p[j]);
if((d-p[i].r-p[j].r)>)
map[i][j]=INF;
else ///相连记录为1
map[i][j]=;
map[i][i]=;
}
spfa();
spfa();
spfa();
if(dis[][]==INF||dis[][]==INF||dis[][]==INF)
{
printf("-1\n");
continue;
}
int xmin=INF;
for(i=; i<=n; i++)
{
if(dis[][i]+dis[][i]+dis[][i]+<xmin)
xmin=dis[][i]+dis[][i]+dis[][i]+;
}
printf("%d\n",n-xmin);
}
return ;
}

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

  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. 模板方法(Template Method)(父类声明算法骨架,子类具体不同实现)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述模板方法(Template Method)模式的: 模板方法模式是类的行为模式.准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式 ...

  2. CPU 和内存 $ free -m$ uptime$ top$ htop

    注意以下问题: 还有空余的内存吗? 服务器是否正在内存和硬盘之间进行swap? 还有剩余的CPU吗? 服务器是几核的? 是否有某些CPU核负载过多了? 服务器最大的负载来自什么地方? 平均负载是多少?

  3. Laravel5.5/6 报错call to undefined function openssl cipher iv length()

    在安装laravel5.5后, 访问显示报错. call to undefined function openssl cipher iv length() 经查为php7.1的OpenSSL扩展加载失 ...

  4. Python 正则表达式解析HTML

  5. golang的包导入import

    import别名/点下划线(1)import关键字的作用:作用是导入该go源文件所依赖的package包.用在go源文件中,紧接在pakage后面的部分.(2)只要在源文件中用到了的package包就 ...

  6. bash 小技巧

    CTRL-R (reverse find),按下之后敲几个字母就能在最近打过的命令里搜索.

  7. day39-Spring 18-Spring的JDBC模板:查询的操作

    package cn.itcast.spring3.demo2; import java.sql.ResultSet; import java.sql.SQLException; import jav ...

  8. 使用cmd发送邮件

    转自:http://www.cnblogs.com/fanyong/p/3498670.html 本文演示用命令行发送邮件的过程. SMTP 首先介绍下smtp协议——简单邮件传输协议 (Simple ...

  9. 字符串Hash算法比较

    基本概念所谓完美哈希函数,就是指没有冲突的哈希函数,即对任意的 key1 != key2 有h(key1) != h(key2).设定义域为X,值域为Y, n=|X|,m=|Y|,那么肯定有m> ...

  10. SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作)

    SWF在线绘本批量制作高质量PDF的新方法(重点在批量制作) 2012-12-21  未来决定...       http://www.ebama.net/thread-107643-1-1.html ...