hdu 3832 Earth Hour(最短路变形)
Earth Hour
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1897    Accepted Submission(s):
748
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.
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.
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.
题意: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(最短路变形)的更多相关文章
- HDU 3832 Earth Hour(最短路)
		
题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...
 - hdu 3832 Earth Hour  (最短路变形)
		
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Tota ...
 - hdu 3832 Earth Hour
		
http://acm.hdu.edu.cn/showproblem.php?pid=3832 #include <cstdio> #include <iostream> #in ...
 - hdu 3832 Earth Hour  bfs
		
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Prob ...
 - hdu 6201 transaction (最短路变形——带负权最长路)
		
题意: 给定n个城市的货物买卖价格, 然后给定n-1条道路,每条路有不同的路费, 求出从某两个城市买卖一次的最大利润. 利润 = 卖价 - (买价 + 路费) 样例数据, 最近是从第一个点买入, 第4 ...
 - HDU 6166 Senior Pan (最短路变形)
		
题目链接 Problem Description Senior Pan fails in his discrete math exam again. So he asks Master ZKC to ...
 - 最短路变形题目 HDU多校7
		
Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting of N ports and M sh ...
 - HDOJ  find the safest road  1596【最短路变形】
		
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
 - POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
		
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
 
随机推荐
- 如何在TypeScript中使用JS类库
			
使用流程 1.首先要清除类库是什么类型,不同的类库有不同的使用方式 2.寻找声明文件 JS类库一般有三类:全局类库.模块类库.UMD库.例如,jQuery是一种UMD库,既可以通过全局方式来引用,也可 ...
 - Linux 中查询 CPU 的核数的方法
			
以一台 Linux 服务器为例.这台 Linux 包括两颗 Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz CPU, 单颗 CPU 包括 10 个 cpu core ...
 - 破逼Json,该死的Json库,操了
			
jansson,就这个库,破几把玩意,本来很简单的Json,就是简单的字符串操作,ATL一个CString就能解决,QT的QSting也能解决,DELPHI的String也能解决.而这B,非把那么简单 ...
 - IbatchBolt和BaseTransactionalBolt区别
			
void prepare(java.util.Map conf, TopologyContext context, BatchOutputCollector collector, T id) T id ...
 - NOIP模拟 6.26
			
T1 子矩阵 题目描述 小A有一个N×M的矩阵,矩阵中1~N*M这(N*M)个整数均出现过一次.现在小A在这个矩阵内选择一个子矩阵,其权值等于这个子矩阵中的所有数的最小值.小A想知道,如果他选择的子矩 ...
 - 各大ACM OJ网址
			
做快乐的程序员 以你的条件,你不必追求优秀,但你可以做到良好. 各大OJ网址 ACM OJ Collection(排名不分先后): 中国:(China) 华东地区: 浙江: 杭州电子科技大学(HDU) ...
 - SDUT-3398_数据结构实验之排序一:一趟快排
			
数据结构实验之排序一:一趟快排 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定N个长整型范围内的整数,要求输出以给 ...
 - 【软件安装】我喜欢的notepad插件
			
1.文件管理器 explorer 2.16进制查看文件工具 HEX-Editor
 - cocos2dx3.0项目创建流程
			
cocos2dx3.0不是beta,新增了wp项目创建的支持 但不知道为啥非beta版本号的tools文件夹中取消了project-creator,可能有更改吧 没有这个工具还挺麻烦.就自己手动创建c ...
 - ImmutableMap不可使用null的问题
			
示例 在项目中有发现类似下方的代码, Map tmpParams = ImmutableMap.of( "extraInfos", ext.get("extraInfos ...