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. JSP-http和tomcat

    一 Http 1.1 javaweb概述 1.2 http协议的概述 1.什么是Http协议 HTTP,超文本传输协议(HyperText Transfer Protocol)是互联网上应用最为广泛的 ...

  2. tinkcmf视频上传大小限制

    /application/Common/Common/function.php 找到upload_max_filesize把后面的数值改成合适的大小(单位是KB)

  3. Linux系统下实现远程连接MySQL数据库的方法教程

    1.在服务器端开启远程访问首先进入mysql数据库,然后输入下面两个命令: grant all privileges on *.* to 'root'@'%' identified by 'passw ...

  4. 运行Jmeter时,响应数据中文乱码问题解决办法

    需要修改jmeter中的配置,在Jmeter安装目录/bin/jmeter.properties文件中进行修改: sampleresult.default.encoding默认为ISO-8859-1, ...

  5. 安装docker报错问题

    安装docker容易出现错误的几种情况: 1.网络问题,无法下载完成的docker容器 2.linux内核版本必须是3.10及以上 3.可以选择使用aliyun的yum源,更好用 4.

  6. BZOJ 3057圣主的考验题解

    老师居然考这么毒瘤的题目!!!!! 很容易想到dp,f[i][j]表示有i个节点,左子树的最深深度为j的方案数 枚举左子树有多少节点然后转移,复杂度为n^3 T飞~ 我们考虑到有深度为h的树的节点有多 ...

  7. CC-Debugger 最小调试接法

    CC-Debugger 最小调试接法 以 CC2541 为例,最少需要四根 DD DC RST GND. 一般 VCC 目标调试板都有,所以这里你需要将 CC-Debugger 的 PIN 2 和 P ...

  8. JavaScript--兼容问题总结

    以下兼容主要面向IE8以上的兼容. 一.window.navigator浏览器信息 <script> console.log(window.navigator); // 用户浏览器的类型 ...

  9. 数组map用法总结

    数组中,map方法,指的是是数组的映射. map基本语法如下:function回调支持3个参数,第1个是遍历的数组内容:第2个是对应的数组索引,第3个是数组本身. map方法的作用不难理解,“映射”嘛 ...

  10. Request.Cookies和Response.Cookies

    Request.Cookies创建的Cookie只能用于后台不能用于HTML的前台Response.Cookies操作过的Cookie,所有方法获取到的都是被更新过的值,也就是说Response.Co ...