hdu 3832 Earth Hour
http://acm.hdu.edu.cn/showproblem.php?pid=3832
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#define maxn 1001
using namespace std;
const int inf=<<; int g[maxn][maxn];
bool vis[maxn];
int dis1[maxn],dis2[maxn],dis3[maxn];
int n;
struct node
{
int x,y,r;
}p[maxn];
int sqr(int x)
{
return x*x;
} void spfa(int src,int dis[])
{
queue<int>q;
memset(vis,false,sizeof(vis));
for(int i=; i<=n; i++) dis[i]=inf;
dis[src]=;
vis[src]=true;
q.push(src);
while(!q.empty())
{
int u=q.front(); q.pop();
vis[u]=false;
for(int i=; i<n; i++)
{
if(dis[i]>dis[u]+g[u][i]&&g[u][i]!=inf)
{
dis[i]=dis[u]+g[u][i];
if(!vis[i])
{
q.push(i);
vis[i]=true;
}
}
}
}
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i==j) g[i][j]=;
else g[i][j]=inf;
}
}
for(int i=; i<n; i++)
{
cin>>p[i].x>>p[i].y>>p[i].r;
}
for(int i=; i<n; i++)
{
for(int j=i+; j<n; j++)
{
if(sqrt(sqr(p[i].x-p[j].x)+sqr(p[i].y-p[j].y))<=(p[i].r+p[j].r))
{
g[i][j]=g[j][i]=;
}
}
}
spfa(,dis1);
spfa(,dis2);
spfa(,dis3);
int min1=inf;
for(int i=; i<n; i++)
{
//printf("%d %d %d\n",dis1[i],dis2[i],dis3[i]);
min1=min(min1,dis1[i]+dis2[i]+dis3[i]);
}
if(min1==inf) printf("-1\n");
else printf("%d\n",n-min1-);
}
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 bfs
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Prob ...
- hdu 3832 Earth Hour(最短路变形)
Earth Hour Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total ...
- 【HDOJ】3832 Earth Hour
其实就是bfs,不过也可以写成最短路,因为权重为1,可以用Spira解. /* 3832 */ #include <iostream> #include <string> #i ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 【转】最短路&差分约束题集
转自:http://blog.csdn.net/shahdza/article/details/7779273 最短路 [HDU] 1548 A strange lift基础最短路(或bfs)★254 ...
随机推荐
- cf C. Matrix
http://codeforces.com/contest/365/problem/C 构造出的矩阵中的长方形的和等于构成它的长的那些数字的和加上构成它的宽的那些数字的和. 也就是求这个字符串中的两个 ...
- codeforces Ilya and Matrix
http://codeforces.com/contest/313/problem/C #include <cstdio> #include <cstring> #includ ...
- Codeforces 478D Red-Green Towers
http://codeforces.com/problemset/problem/478/D 思路:dp:f[i][j]代表当前第i层,用了j个绿色方块的方案数,用滚动数组,还有,数组清零的时候一定要 ...
- Row Cache Objects
This latch comes into play when user processes are attempting to access or update the cached data di ...
- 【转】Install SmartGit via PPA in Ubuntu 13.10/13.04/12.04/Linux Mint
原文网址:http://ubuntuhandbook.org/index.php/2013/09/install-smartgit-via-ppa-ubuntu-linux-mint/ This tu ...
- poj2752 Seek the Name, Seek the Fame
Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and ...
- HTML5的local storage存储的数据到底存到哪去了
原文地址:http://zhidao.baidu.com/link?url=m6p5MLv0R46lDCd_Vnrry4XOMbdCwgV5fzs3tj5Jeyht1nPkAZ9OrO23njYBY1 ...
- URAL 1658
题目大意:求出T个最小的满足各个位的和为S1,平方和为S2的数.按顺序输出.数的位数大于100或者不存在这样一个数时,输出:No solution. KB 64bit IO Format:%I ...
- WPF - ViewModle中关闭Window
在Binding close event时候,需要从ViewModel关闭Window. 一个很简洁的解决方案就是,将Window 当做CommandParameter传过去. Command=&qu ...
- Bootstrap--本地安装使用
1.到官网下载:http://v2.bootcss.com 2.下载后是一个压缩文件,把它放在相应的工作目录下,然后解压. 3.新建一个测试文件,然后导入两个文件.