POJ 2349 Arctic Network
来源:互联网 发布:人才招聘源码 码农网 编辑:程序博客网 时间:2024/06/05 09:08
题意:在若干个村庄之间需要有卫星天线和无线发信器,卫星天线之间的通讯可以无视距离,无线发信器之间通讯有距离限制,已知每个村庄的坐标,已经卫星天线的个数以及村庄的个数,求无线发信器的通讯距离至少要多少
链接:http://poj.org/problem?id=2349
思路:求最小生成树上的第k大边权,建图后利用模板求出最小生成树,利用dis数组的性质求出第k大边权
注意点:无
以下为AC代码:
Run IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time14176789luminous112349Accepted2724K47MSG++4433B2015-05-09 09:53:55/* ************************************************# @Author : Luminous11 (573728051@qq.com)*# @Date : 2015-04-20 20:15:06*# @Link : http://blog.csdn.net/luminous11 *********************************************** */#include <algorithm>#include <iostream>#include <climits>#include <iomanip>#include <cstdlib>#include <cstring>#include <cctype>#include <cstdio>#include <string>#include <vector>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <deque>#include <list>#include <map>#include <set>//#include <unordered_map>//#include <unordered_set>#define pb push_back#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define READ(f) freopen(f, "r", stdin)#define WRITE(f) freopen(f, "w", stdout)#define clr(a, v) memset( a , v , sizeof(a) )#define RS(s) scanf ( "%s", s )#define RDI(a) scanf ( "%d", &a )#define RDII(a, b) scanf ( "%d%d", &a, &b )#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c )#define PL() printf ( "\n" )#define PI(a) printf ( "%d", a )#define PIL(a) printf ( "%d\n", a )#define PSL(s) printf ( "%s\n", s )#define PII(a,b) printf ( "%d %d", a, b )#define PIIL(a,b) printf ( "%d %d\n", a, b )#define PIII(a,b,c) printf ( "%d %d %d", a, b, c )#define PIIIL(a,b,c) printf ( "%d %d %d\n", a, b, c )#define rep(i,m,n) for ( int i = m; i < n; i ++ )#define REP(i,m,n) for ( int i = m; i <= n; i ++ )#define dep(i,m,n) for ( int i = m; i > n; i -- )#define DEP(i,m,n) for ( int i = m; i >= n; i -- )#define repi(i,m,n,k) for ( int i = m; i < n; i += k )#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )#define depi(i,m,n,k) for ( int i = m; i > n; i += k )#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )//#pragma comment ( linker, "/STACK:1024000000,1024000000" )using namespace std;template <class T>inline bool RD ( T &ret ){ char c; int sgn; if ( c = getchar(), c ==EOF )return 0; //EOF while ( c != '-' && ( c < '0' || c > '9' ) ) c = getchar(); sgn = ( c == '-' ) ? -1 : 1; ret = ( c == '-' ) ? 0 : ( c - '0' ); while ( c = getchar() , c >= '0' && c <= '9' ) ret = ret * 10 + ( c - '0' ); ret *= sgn; return 1;}inline void PD ( int x ){ if ( x > 9 ) PD ( x / 10 ); putchar ( x % 10 + '0' );}const double eps = 1e-10;const double pi = acos(-1.0);const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };struct node{ int x, y, cnt; node(){} node( int _x, int _y ) : x(_x), y(_y) {} node( int _x, int _y, int _cnt ) : x(_x), y(_y), cnt(_cnt) {}};struct edge{ int u, v; double wei; edge(){} edge( int _u, int _v, double _w ) : u(_u), v(_v), wei(_w) {}};bool operator< ( const edge & a, const edge &b ){ return a.wei < b.wei;}int s, p;double ans;node num[505];double g[505][505];double dis[505];bool vis[505];double calc ( int u, int v ){ int x = num[u].x - num[v].x; int y = num[u].y - num[v].y; double dis = sqrt ( x * x + y * y ); return dis;}void init(){ clr ( num, 0 ); clr ( vis, 0 ); rep ( i, 0, 505 ){ dis[i] = 0.0; rep ( j, 0, 505 ){ g[i][j] = 1000000000; } }}void prim(){ REP ( i, 1, p ){ dis[i] = g[1][i]; } dis[1] = 0.0; rep ( k, 0, p ){ double _min = 100000000.0; int l = -1; REP ( i, 1, p ){ if ( ! vis[i] && _min > dis[i] ){ _min = dis[i]; l = i; } } vis[l] = 1; REP ( i, 1, p ){ if ( ! vis[i] && dis[i] > g[l][i] ){ dis[i] = g[l][i]; } } }}bool cmp ( const int &a, const int &b ){ return a > b;}int main(){ int T; RDI ( T ); while ( T -- ){ init(); RDII ( s, p ); int v, u, w; REP ( i, 1, p ){ RDII ( u, v ); num[i] = node ( u, v ); } int cnt = 0; REP ( i, 1, p ){ REP ( j, i + 1, p ){ g[i][j] = g[j][i] = calc ( i, j ); } } prim(); sort ( dis, dis + p + 1, cmp ); cout << fixed << setprecision(2) << dis[s-1] << endl; } return 0;}
0 0
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- poj 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- POJ-2349-Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- Poj 2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349 Arctic Network
- POJ 2349 Arctic Network
- POJ-2349-Arctic Network
- poj 2349 Arctic Network
- Extjs4.2密码框两次判断和日期判断
- 强类型语言和弱类型语言
- Github Gitorious
- Github上的andoird开源组件整理
- 15第九周项目二——Time类中的运算符的重载(续)
- POJ 2349 Arctic Network
- runtime运行机制
- 虚拟设备创建多分区虚拟磁盘(软盘,硬盘)
- R软件学习笔记-1
- 函数ZwQuerySystemInformation小结
- 递归的应用实战一
- stm8 蜂鸣器BEEP
- 检查被修改的参数-被修改的时间及前后值
- VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径