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大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
随机推荐
- 锋利的jQuery学习笔记之jQuery选择器
在介绍jQuery选择器之前,先简单介绍一下CSS选择器---> 一.CSS选择器 常见的CSS选择器有以下几种: 选择器 语法 描述 示例 标签选择器 E{CSS规则} 以文档元素为选择符 t ...
- 通过inputSplit分片size控制map数目
前言:在具体执行Hadoop程序的时候,我们要根据不同的情况来设置Map的个数.除了设置固定的每个节点上可运行的最大map个数外,我们还需要控制真正执行Map操作的任务个数. 1.如何控制实际运行的m ...
- NOIP模拟 9.09
AK300分 果实计数 (count.pas/.c/.cpp) 时间限制:1s,空间限制32MB 题目描述: 淘淘家有棵奇怪的苹果树,这棵树共有n+1层,标号为0~n.这棵树第0层只有一个节点,为根节 ...
- 洛谷P2327 [SCOI2005]扫雷 [2017年5月计划 清北学堂51精英班Day1]
P2327 [SCOI2005]扫雷 题目描述 输入输出格式 输入格式: 第一行为N,第二行有N个数,依次为第二列的格子中的数.(1<= N <= 10000) 输出格式: 一个数,即第一 ...
- bzoj 3895 取石子——博弈论
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3895 看题解:https://blog.csdn.net/popoqqq/article/d ...
- Python3 中 configparser 使用注意事项
在使用configparser时候应注意: ①配置文件(ini文件)的存放位置:配置文件和调用文件放在同一个文件包下面. 使用read()函数读取并解析配置文件时,直接写配置文件(ini文件)的文件名 ...
- LintCode刷题笔记-- BackpackII
标记: 动态规划 问题描述: Given n items with size Ai, an integer m denotes the size of a backpack. How full you ...
- 【JZOJ5064】【GDOI2017第二轮模拟day2】友好城市 Kosarajo算法+bitset+ST表+分块
题面 在Byteland 一共有n 座城市,编号依次为1 到n,这些城市之间通过m 条单向公路连接. 对于两座不同的城市a 和b,如果a 能通过这些单向道路直接或间接到达b,且b 也能如此到达a,那么 ...
- FileIntputStream / FileOutputStream 类
FileInputStream类(重点) (1)基本概念 java.io.FileInputStream类用于读取诸如图像之类的原始字节流. (2)常用的方法 FileInputStrea ...
- docker容器时区问题
原文:docker容器时区问题 版权声明:本文为博主原创文章,随意转载. https://blog.csdn.net/Michel4Liu/article/details/80890868 本系列目录 ...