题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2429

题解:从某一点遍历n个点,且使最长边最短,就是MST了。

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 1000+5

 #define maxm 200000+5

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go)

 #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)

 #define mod 1000000007
#define sqr(x) (x)*(x) using namespace std; inline int read() { int x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
int n,m;
double mx,b[maxn],d[maxn];
bool v[maxn];
struct rec{int x,y;}a[maxn];
priority_queue<pa,vector<pa>,greater<pa> >q;
inline double dist(int x,int y){return sqrt(sqr(a[x].x-a[y].x)+sqr(a[x].y-a[y].y));}
inline void prim()
{
for1(i,n)d[i]=inf;
d[]=;
q.push(pa(,));
while(!q.empty())
{
int x=q.top().second;q.pop();
if(v[x])continue;v[x]=;
if(d[x]>mx)mx=d[x];
for1(i,n)if(!v[i]&&dist(i,x)<d[i])
{
d[i]=dist(i,x);
q.push(pa(d[i],i));
}
}
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); m=read();
for1(i,m)b[i]=read();
n=read();
for1(i,n)a[i].x=read(),a[i].y=read();
prim();
int ans=;
for1(i,m)if(b[i]>=mx)ans++;
cout<<ans<<endl; return ; }

BZOJ2429: [HAOI2006]聪明的猴子的更多相关文章

  1. BZOJ2429[HAOI2006]聪明的猴子[最小生成树 kruskal]

    2429: [HAOI2006]聪明的猴子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 896  Solved: 575[Submit][Statu ...

  2. [BZOJ2429][HAOI2006]聪明的猴子(MST)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2429 分析:要让最大的最小,所以就是最小生成树上的啦,于是问题就变成了有多少个猴子&g ...

  3. [BZOJ2429][HAOI2006]聪明的猴子(最小生成树)

    性质:最小生成树上任意两点间的最大边权,一定是这两点间所有路径的最大边权中最小的.证明显然. #include<cstdio> #include<cstring> #inclu ...

  4. 最小生成树 2429: [HAOI2006]聪明的猴子

    BZOJ 2429: [HAOI2006]聪明的猴子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 877  Solved: 566[Submit][ ...

  5. 最小生成树——[HAOI2006]聪明的猴子

    题目:[HAOI2006]聪明的猴子 描述: [题目描述] 在一个热带雨林中生存着一群猴子,它们以树上的果子为生.昨天下了一场大雨,现在雨过天晴,但整个雨林的地表还是被大水淹没着, 猴子不会游泳,但跳 ...

  6. BZOJ 2429: [HAOI2006]聪明的猴子( MST )

    水题, 求MST即可. -------------------------------------------------------------------------------- #includ ...

  7. 2429: [HAOI2006]聪明的猴子

    2429: [HAOI2006]聪明的猴子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 448  Solved: 309[Submit][Statu ...

  8. 洛谷—— P2504 [HAOI2006]聪明的猴子

    P2504 [HAOI2006]聪明的猴子 题目描述 在一个热带雨林中生存着一群猴子,它们以树上的果子为生.昨天下了一场大雨,现在雨过天晴,但整个雨林的地表还是被大水淹没着,部分植物的树冠露在水面上. ...

  9. 洛谷——P2504 [HAOI2006]聪明的猴子

    P2504 [HAOI2006]聪明的猴子 题目描述 在一个热带雨林中生存着一群猴子,它们以树上的果子为生.昨天下了一场大雨,现在雨过天晴,但整个雨林的地表还是被大水淹没着,部分植物的树冠露在水面上. ...

随机推荐

  1. 《C++Primer》复习——with C++11 [1]

    1.头文件中不应包含using声明,因为头文件的内容会拷贝到所有引用到他的文件中去,如果头文件里有谋个using声明,那么每个使用了该头文件的文件就会有这个声明,由于不经意间包含了一些名字,反而可能产 ...

  2. centos nginx,php添加到Service

    SHELL脚本: nginx vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx da ...

  3. java多线程状态转换

    http://www.mamicode.com/info-detail-517008.html 相关资料链接 我觉得下面这张图总结的很好

  4. VMware vSphere HyperVisor安装过程记录

      作者:sdjnzqr 出处:http://www.cnblogs.com/sdjnzqr/ 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文 ...

  5. 基于密度的聚类之Dbscan算法

    一.算法概述 DBSCAN(Density-Based Spatial Clustering of Applications with Noise)是一个比较有代表性的基于密度的聚类算法.与划分和层次 ...

  6. 【技术贴】解决MySql连接不上 ip远程连接Host is not allowed to conn

    落雨 如果你想连接远程IP的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ...

  7. PHP之SQL防注入代码(360提供)

    <?php class sqlsafe { private $getfilter = "'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\ ...

  8. mysql导出多个表数据为excel方法,substring函数查询

    //查询sys_username以S.00655开头的用户 ),sys_password FROM `tbl_sa_syslogin` where sys_username like 'S.%'; / ...

  9. MVC中SelectList和@Html.DropDownList("MainDuty_UserId","请选择")的运用

    Models.Project model = projectdb.dbSet.SingleOrDefault(e => e.Project_ID == id);            ViewB ...

  10. C#接口的经典案例

    C#接口(interface)实例子(简单而经典)2008/12/04 10:04using System; using System.Collections.Generic; using Syste ...