Earth Hour(最短路)
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
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.
Output
Note that if none of the lights is turned off and the three places are still not connected. Just output -1.
Sample Input
Sample Output
#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 ;
}
Earth Hour(最短路)的更多相关文章
- 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(最短路)
题目地址:HDU 3832 这个题的这种方法我无法给出证明. 我当时这个灵感出来的时候是想的是要想覆盖的点最少,那就要尽量反复利用这些点,然后要有两个之间是通过还有一个点间接连接的,这样会充分利用那些 ...
- hdu 3832 Earth Hour(最短路变形)
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
- Codeforces Round #406 (Div. 1) B. Legacy 线段树建图跑最短路
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...
- Codeforces 787D. Legacy 线段树建模+最短路
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces787D(SummerTrainingDay06-D 线段树+最短路)
D. Legacy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- CF 787D Legacy(线段树思想构图+最短路)
D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 转载 - 最短路&差分约束题集
出处:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★ ...
随机推荐
- wp8使用mvvm模式简单例子(二)---登陆功能,事件触发
首先,还是需要一个Model类来为UI层的元素提供数据源 public class LoginModel:DependencyObject { public string Uid { get { re ...
- Keepalived高可用集群应用
Keepalived高可用集群应用 1.keepalived服务说明 1.1.keepalived介绍 Keepalived是一个用C语言编写的路由软件.该项目的主要目标是为Linux系统和基于Lin ...
- [Fri, 3 Jul 2015 ~ Tue, 7 Jul 2015] Deep Learning in arxiv
Convolutional Color Constancy can this be used for training cnn to narrow the gap between different ...
- python可hash 不可hash类型
不可变类型是可hash #tuple str freezeset 可变类型是不可hash ##list set
- linux程序设计——取消一个线程(第十二章)
12.7 取消一个线程 有时,想让一个线程能够要求还有一个线程终止,就像给它发送一个信号一样. 线程有方法能够做到这一点,与与信号处理一样.线程能够被要求终止时改变其行为. pthread_ca ...
- UINavigationController改变动画效果
@interface UINavigationController (CustomTransition) - (void) pushWithCustomAnimation:(UIViewControl ...
- 了解MVC框架开发
版权声明:本文为博主原创文章,未经博主允许不得转载. 前言:本篇文章我们浅谈下MVC各个部分,模型(model)-视图(view)-控制器(controller), 以及路由. 对于使用MVC的好处大 ...
- Hibernate学习之二级缓存
© 版权声明:本文为博主原创文章,转载请注明出处 二级缓存 - 二级缓存又称“全局缓存”.“应用级缓存” - 二级缓存中的数据可适用范围是当前应用的所有会话 - 二级缓存是可插拔式缓存,默认是EHCa ...
- Windows 10 优化
---恢复内容开始--- 0x00 使开始菜单,任务栏,和操作中心透明 --关闭 右下角开始菜单,选择设置,打开个性化菜单,找到颜色一栏.向下滑至最低端,使开始菜单,任务栏,和操作中心透明选项关闭 0 ...
- Android版CSDN发现的一些问题
作为CSDN的忠有用户,在他一推出这款APP以后.就下载了使用,近期发现了一些个问题,在此提出来.希望看到或者遇到同样问题的,提出你们的解决方式. 在CSDN手机版的首页上,我 ...