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大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
随机推荐
- angular4 动态创建组件 vs 动态创建模板
实现 模拟场景:页面上"帮助"按钮的点击触发帮助文档的弹出框,且每个页面的帮助文档不一样 因此弹出框里的帮助文档是一个动态模板而不是动态组件 以下comp均代表Type类型的动态 ...
- OSI层次关系
一.OSI参考模型 今天我们先学习一下以太网最基本也是重要的知识——OSI参考模型. 1.OSI的来源 OSI(Open System Interconnect),即开 ...
- update当根据条件不同时 更新同一个字段的方法 或多表插入
1.通过存储过程 循环 传值 create or replace procedure p_u isbegin for rs in (select distinct (rks) from rkbz)lo ...
- vagrant简介
什么是vagrant? 简单理解,就是可以通过Vagrant这个工具管理虚拟机,比如说想创建一个centos环境的虚拟机,不需要安装系统这么麻烦,通过vagrant可以快速创建 官网地址:https: ...
- 【洛谷P1207】双重回文数 【USACO1.2】
P1207 [USACO1.2]双重回文数 Dual Palindromes 题目描述 如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做"回文数".例如,12321就是一 ...
- pip list报错:DEPRECATION: The default format will switch to columns in the future.
一.现象: pip list 显示出以下错误: DEPRECATION: The default format will switch to columns in the future. Yo ...
- cf round 482D Kuro and GCD and XOR and SUM
题意: 开始有个空集合,现在有两种操作: $(1,x)$:给集合加一个数$x$,$x \leq 10^5$; $(2,x,k,s)$:在集合中找一个$a$,满足$a \leq s-x$,而且$k|gc ...
- SSH 相关基础
检查是否安装: sudo apt-cache policy openssh-client sudo apt-cache policy openssh-server 也可直接用 sudo apt-ca ...
- 在vue项目中同时使用element-ui和mint-ui,的时候,.babelrc配置文件怎么写
我们安装vue组件库的时候,考虑到大小问题,需要根据需要仅引入部分组件 借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的. 但是在配置 .bab ...
- 链表源代码(C语言实现)
源代码(C语言实现) ①.构造链表节点 typedef struct Node //一个单独的节点 { int ...