hdu 3832 Earth Hour bfs
Earth Hour
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
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.
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.
Note that if none of the lights is turned off and the three places are still not connected. Just output -1.
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
2
1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-6
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e3+,M=1e6+,inf=1e9+;
const LL INF=5e17+,mod=1e9+; vector<int>edge[N];
int x[N],y[N],r[N];
int vis[N],dis[N];
int check(int i,int j)
{
if((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<=(r[i]+r[j])*(r[i]+r[j]))
return ;
return ;
}
int bfs(int s,int t)
{
queue<int>q;
q.push(s);
memset(vis,,sizeof(dis));
dis[s]=;
vis[s]=;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=;i<edge[u].size();i++)
{
int v=edge[u][i];
if(vis[v])continue;
dis[v]=dis[u]+;
vis[v]=;
q.push(v);
}
}
if(vis[t])return dis[t];
return ;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d%d",&x[i],&y[i],&r[i]),edge[i].clear();
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(check(i,j))
{
edge[i].push_back(j);
edge[j].push_back(i);
}
}
}
int ans=inf;
for(int i=;i<=n;i++)
{
int d1=bfs(i,);
int d2=bfs(i,);
int d3=bfs(i,);
ans=min(ans,d1+d2+d3+);
}
if(ans>n)printf("-1\n");
else printf("%d\n",n-ans);
}
return ;
}
hdu 3832 Earth Hour bfs的更多相关文章
- HDU 3832 Earth Hour(最短路)
题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...
- hdu 3832 Earth Hour
http://acm.hdu.edu.cn/showproblem.php?pid=3832 #include <cstdio> #include <iostream> #in ...
- 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(最短路变形)
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)
题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...
- hdu 2102 A计划-bfs
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- HDU 1072(记忆化BFS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意:走迷宫.走到装置点重置时间,到达任一点时的时间不能为0,可以走重复路,求出迷宫最短时 ...
- HDU 2364 (记忆化BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2364 题目大意:走迷宫.从某个方向进入某点,优先走左或是右.如果左右都走不通,再考虑向前.绝对不能往 ...
- HDU 2579 (记忆化BFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2579 题目大意:走迷宫.对于障碍点,只有当前(dep+1)%k才能走,问最少时间. 解题思路: 只有 ...
随机推荐
- GoldenGate 12.3发布
新特性: oracle db1. 支持12.2 oracle db2. 支持微服务架构, 可以使用restful api 管理OGG3. Parallel replicat,性能比integrated ...
- 用WPE+CCproxy+自动代理截取安卓游戏封包
wpe三件套:https://pan.baidu.com/s/19gI2GPZ0iuu4wpKljCOn4A 用WPE+CCproxy+自动代理截取安卓游戏封包>>
- MySQL字符类型datetime与timestamp
这片博客来详细分区一下这哥俩! 首先来说明这两个字符类型: DATETIME 8 1000-01-01 00:00:00 ~9999~12-31 23:59:59 0000-00-00 00:00:0 ...
- EDK II之USB主控制器(EHCI)驱动的实现框架
本文简要介绍一下UEFI中EHCI驱动的代码实现框架: 下图是HCDI: 上图是Host驱动程序向上层驱动提供的接口图: 1.大部分接口的最后动作都是去操作主控制器寄存器,ECHI的spec:< ...
- mysql 通过查看mysql 配置参数、状态来优化你的mysql
我把MYISAM改成了INNODB,数据库对CPU方面的占用变小很多' mysql的监控方法大致分为两类: 1.连接到mysql数据库内部,使用show status,show variables,f ...
- Navicat使用ssh连接数据库
1.主机名或ip地址必须填localhost 2.主机名或ip地址必须填外网ip地址
- CI(CodeIgniter)框架下使用非自带类库实现邮件发送
在项目开发过程中,需要到了邮件提醒功能.首先想到的是CI自身带不带邮件发送类,查看帖子,发现CI本身自带,然后试着利用CI自身带的类库来实现,经过搜搜很多帖子,不少开发者反馈CI自身的Email类有问 ...
- spring使用@Autowired为抽象父类注入依赖
有时候为了管理或者避免不一致性,希望具体服务统一继承抽象父类,同时使用@Autowired为抽象父类注入依赖.搜了了网上,有些解决方法实现实在不敢恭维,靠子类去注入依赖,那还有什么意义,如下: 父类: ...
- Android之socket服务端
import java.io.DataInputStream; import java.io.IOException; import java.io.PrintWriter; import java. ...
- Centos7.03搭建JDK、Tomcat、MySql环境
本人linux服务器配置是:centos_7_03_64_20G_xdragon_20171025.vhd 公网IP:106.14.14.224 内存:2GB SecureCRT8.0:https:/ ...