Earth Hour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)

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
 
Source
#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的更多相关文章

  1. HDU 3832 Earth Hour(最短路)

    题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...

  2. hdu 3832 Earth Hour

    http://acm.hdu.edu.cn/showproblem.php?pid=3832 #include <cstdio> #include <iostream> #in ...

  3. hdu 3832 Earth Hour (最短路变形)

    Earth Hour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Tota ...

  4. hdu 3832 Earth Hour(最短路变形)

    Earth Hour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total ...

  5. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

  6. hdu 2102 A计划-bfs

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  7. HDU 1072(记忆化BFS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1072 题目大意:走迷宫.走到装置点重置时间,到达任一点时的时间不能为0,可以走重复路,求出迷宫最短时 ...

  8. HDU 2364 (记忆化BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2364 题目大意:走迷宫.从某个方向进入某点,优先走左或是右.如果左右都走不通,再考虑向前.绝对不能往 ...

  9. HDU 2579 (记忆化BFS搜索)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2579 题目大意:走迷宫.对于障碍点,只有当前(dep+1)%k才能走,问最少时间. 解题思路: 只有 ...

随机推荐

  1. 2、在VM上的 CentOS 6.5 上安装mysql

    1.查看系统是否安装了MySQL     使用命令:     #rpm -qa | grep mysql 2.卸载已安装的MySQL      卸载mysql命令如下:       #rpm -e - ...

  2. echart中间显示固定的字

  3. MyEclipse新建Server项目

  4. Android 新老两代 Camera API 大起底

    https://blog.csdn.net/Byeweiyang/article/details/80515192 0.背景简介 最近有一部分相机相关的需求,专注于对拍摄的照片.视频的噪点.色温.明暗 ...

  5. 一个用python简单的封装了aria2的jsonrpc中adduri的脚本

    aria2是一个十分牛逼的下载神器,有时候项目需要一个很牛逼的下载中间件的话,aria2是一个不错的选择.其中支持jsonrpc和websocket的特性尤其诱人.但是python用起来还是有点不爽, ...

  6. 《学习OpenCV3》第6章课后习题

    //Exercises at end of Chapter 5,<learning OpenCV3> #include "stdafx.h" #include < ...

  7. 20145320周岐浩 web安全基础实践

    20145320周岐浩 web安全基础实践 一.实验后回答问题 (1)SQL注入攻击原理,如何防御 一.SQL注入攻击原理 SQL注入攻击值得是通过构建特殊的输入作为参数传入web应用程序,而这些输入 ...

  8. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  9. 配置named服务之前的 相关术语意思

    putty: [p^ti]: 油灰, 腻子,像 clay 粘土一样起 连接作用. 非常简洁,只有500多kB, 不需要安装,纯绿色的,版本还是0.x, Simon Tatham, 甚至没有主界面,没有 ...

  10. Linux/shell: remove adjacent similar patterns

    cat > temp004AA1abcAA2AA3abcAA4abcAA5AA6 awk 'BEGIN {pre=0; str="";} { if(NR==1){     i ...