題意:給出一百個點的座標,任意兩點之間都有邊,求將所有點連線起來的最短的所有邊長和
思路:最小生成樹模板,稠密圖,對邊的長度進行篩選即可
注意點:無
以下為ac**:
run id
submit time
judge status
pro.id
exe.time
exe.memory
code len.
language
author
13162929
2015-03-18 13:37:43
accepted
1875
171ms
2196k
5231 b
g++luminous11
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include #define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#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 rs(s) scanf ( "%s", s )
#define pi(a) printf ( "%d", a )
#define pil(a) printf ( "%d\n", a )
#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 pl() printf ( "\n" )
#define psl(s) printf ( "%s\n", s )
#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 )
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
template inline bool rd ( t &ret )
inline void pd ( int x )
const double eps = 1e-10;
const int dir[4][2] = ;
struct node
node( int _x, int _y ) : x(_x), y(_y) {}
node( int _x, int _y, int _cnt ) : x(_x), y(_y), cnt(_cnt) {}
node( int _x, int _y, double _dis ) : x(_x), y(_y), dis(_dis) {}
friend bool operator < ( const node &a, const node &b )
}p[105];
int n;
double ans;
priority_queuepq;
double calc ( int x, int y )
int fa[105];
int ran[105];
int find( int x )
bool kruskal()
else
ans += tmp.dis;
}if ( cnt == n )return true;
}return false;
}void init()
int main()
double tmp;
ans = 0.0;
rep ( i, 0, n )}}
if ( kruskal() )
else
}return 0;
}
HDOJ 1875 暢通工程再續
這個暢通工程還是一交就過,看來暢通工程用來入門是最好了,以後拿這些來掛就不會那麼打擊人了,天天開心。這裡求最小生成樹之前要自己構圖,很簡單就是求出點到點之間的距離,如果距離大於1000和小於10都視作不連通。點少,還是prim就好了。不過這裡存在不連通的情況,不想前面的的工程那麼暢通,最後加乙個迴圈...
1875 暢通工程再續
零基礎學演算法135 include using namespace std include const double inf 0x3f3f3f3f 1.0 struct node double d 105 105 int c 島嶼個數 void prim int count 1 for int i...
hdu 1875 暢通工程再續
題目 又是最小生成樹。一開始錯了幾次。我以為是當兩段路大於1000或者小於10就會不符合要求。其實是讀錯題意了。當兩段路大於1000或者小於10。只應該把這段路變成死路。下面是ac include includeusing namespace std define n 9999999 int n d...