Earth Hour

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1970    Accepted Submission(s): 781

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
 
T 个数据,2D 平面内 n (>=3)个点,再 n 行 x , y , r 表示(x,y)位置的灯照射半径为 r ,要 1 ,2 , 3 点,连通并都照亮,问最多可以关掉几盏灯
//这道题有点难,先要把数据抽象成一个图,如果两两可以连通则设距离为 1 ,不能连通设为 INF 然后分别求1,2,3,这三个点到其余点的最短路径,3个结果都加起来后,那个最小值的点理解为从这点出发,连通1,2,3三个点最短路径,也可以说是最少需要开几盏灯(这个值不会有重复计算的灯),n-之 就是答案
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std; #define MAXN 205
#define INF 100000000 struct Node
{
int x,y;
int r;
}node[MAXN];
int G[MAXN][MAXN]; //连通关系
int dis[MAXN];
int vis[MAXN];
int res[MAXN]; void dij(int n,int p)
{
for (int i=;i<=n;i++)
{
dis[i]=G[p][i];
vis[i]=;
}
dis[p]=;
vis[p]=; for (int i=;i<n;i++)
{
int mp,mmm=INF;
for (int j=;j<=n;j++)
if (!vis[j]&&dis[j]<mmm)
{
mmm=dis[j];
mp=j;
}
if (mmm==INF)
break;
vis[mp]=;
for (int j=;j<=n;j++)
{
if (!vis[j]&&dis[mp]+G[mp][j]<dis[j])
dis[j]=dis[mp]+G[mp][j];
}
}
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for (int i=;i<=n;i++)
{
int x,y,r;
scanf("%d%d%d",&x,&y,&r);
node[i]=(Node){x,y,r};
for (int j=;j<=i;j++)
{
double dist = sqrt((node[j].x-x)*(node[j].x-x)*1.0+(node[j].y-y)*(node[j].y-y)*1.0);
if (dist-(node[j].r+r)<1e-)
G[i][j]=G[j][i]=;
else
G[i][j]=G[j][i]=INF;
}
}
memset(res,,sizeof(res));
dij(n,);
for (int i=;i<=n;i++)
res[i]+=dis[i];
dij(n,);
for (int i=;i<=n;i++)
res[i]+=dis[i];
dij(n,);
for (int i=;i<=n;i++)
res[i]=n-(res[i]+dis[i]+);
int ans=-;
for (int i=;i<=n;i++)
ans=max(ans,res[i]);
printf("%d\n",ans);
}
return ;
}

最新文章

  1. Java 反射调用动态方法
  2. 关于Java语言和面向对象记录
  3. apache ab压力测试
  4. Intellij Idea 14 生成serialVersionUID的方法
  5. cocos2d-x 音乐播放猜想
  6. python文件目录遍历保存成xml文件代码
  7. hdu149850 years, 50 colors (多个最小顶点覆盖)
  8. Windows桌面快捷图标上的小箭头的恢复
  9. Java提高十七:TreeSet 深入分析
  10. 2019腾讯WXG移动客户端暑期实习面经
  11. SDOI2019 省选前模板整理
  12. 【网站管理6】_一个网站SEO优化方案
  13. JAVA-数据库之删除记录
  14. centos 中sshd莫名其妙不见了?
  15. 怎样实现SDO服务
  16. 【转载】细说 Form (表单)
  17. Android Activity 无法获取组件尺寸
  18. 找球号(三)南阳acm528(异或&#39; ^ &#39;)
  19. mysql 长连接断开问题
  20. HRBUST 1313 火影忍者之~静音

热门文章

  1. SparkStreaming数据源Flume实际案例分享
  2. Gentoo:startx出现Failed to load module问题
  3. Intellij idea远程debug连接tomcat,实现单步调试
  4. 13.1Springboot 之 静态资源路径配置
  5. 最新iOS发布App Store详细图文教程~
  6. 【转】 从输入 URL 到页面加载完成的过程中都发生了什么事情?
  7. 机房收费系统合作版(二)——初识Git
  8. Ros 中的多线程
  9. 那些奇妙的&amp;quot;大师&amp;quot;是怎样炼成的(科学、迷信、心理)
  10. UITextView被键盘遮挡的处理