日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5934】Bomb (强连通分量Tarjan + 缩点)

發(fā)布時(shí)間:2023/12/10 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5934】Bomb (强连通分量Tarjan + 缩点) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

There are?NN?bombs needing exploding.?

Each bomb has three attributes: exploding radius?riri, position?(xi,yi)(xi,yi)?and lighting-cost?cici?which means you need to pay?cici?cost making it explode.?

If a un-lighting bomb is in or on the border the exploding area of another exploding one, the un-lighting bomb also will explode.?

Now you know the attributes of all bombs, please use the?minimum?cost to explode all bombs.

Input

First line contains an integer?TT, which indicates the number of test cases.?

Every test case begins with an integers?NN, which indicates the numbers of bombs.?

In the following?NN?lines, the ith line contains four intergers?xixi,?yiyi,?riri?and?cici, indicating the coordinate of ith bomb is?(xi,yi)(xi,yi), exploding radius is?riri?and lighting-cost is?cici.?

Limits?
-?1≤T≤201≤T≤20?
-?1≤N≤10001≤N≤1000?
-??108≤xi,yi,ri≤108?108≤xi,yi,ri≤108?
-?1≤ci≤1041≤ci≤104

Output

For every test case, you should output?'Case #x: y', where?x?indicates the case number and counts from?1?and?y?is the minimum cost.

Sample Input

1 5 0 0 1 5 1 1 1 6 0 1 1 7 3 0 2 10 5 0 1 4

Sample Output

Case #1: 15

題目大意:

現(xiàn)有N顆炸彈急需引爆。每顆炸彈有三個(gè)屬性:爆炸半徑ri,炸彈位置(xi, yi),還有起爆費(fèi)用ci,即你需要花費(fèi)ci才能引爆這個(gè)炸彈。如果一顆未引爆的炸彈在另一顆炸彈的爆炸半徑邊緣或者其中,則會(huì)被連鎖引爆。此時(shí)你已得知所有炸彈的屬性,用最小的花費(fèi)引爆所有炸彈吧。

解題報(bào)告:

? ?強(qiáng)連通分量 + 縮點(diǎn)。先跑一遍Tarjan把所有可以互相引爆的炸彈縮成一個(gè)點(diǎn),也就是說這些只需要看這些小集合之間的關(guān)系,這些小集合之間由于不存在互相引爆的情況,所以構(gòu)成一個(gè)DAG圖,那么我們引爆所有入度為0的集合就可以了,對于集合內(nèi)部,我們選擇那個(gè)爆炸燃燒最小的花費(fèi)就行了。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e4 + 5;struct Point {ll x, y, r, c; } p[MAX]; struct Edge {int fr,to,ne; } e[2000010]; int head[MAX],id,cnt,tot,index; int n; int DFN[MAX],vis[MAX],stk[MAX],LOW[MAX],bel[MAX],in[MAX]; bool ok(int u, int v) {double res = sqrt(((p[u].x - p[v].x) * (p[u].x - p[v].x) + (p[u].y - p[v].y) * (p[u].y - p[v].y)));if(res <= p[u].r) return 1;return 0; } void add(int u, int v) {e[++tot].to = v;e[tot].ne = head[u];head[u] = tot; } void Tarjan(int x) {DFN[x] = LOW[x] = ++id;stk[++index] = x;vis[x] = 1;for(int i = head[x]; i!=-1; i = e[i].ne) {if(!DFN[e[i].to]) {Tarjan(e[i].to);LOW[x] = min(LOW[x],LOW[e[i].to]);}else if(vis[e[i].to]) {LOW[x] = min(LOW[x],DFN[e[i].to]);}}if(LOW[x] == DFN[x]) {cnt++;while(1) {int tmp = stk[index];index--;bel[tmp] = cnt;vis[tmp]=0;if(tmp == x) break;}}} void init() {for(int i = 1; i<=n; i++) {head[i]=-1;DFN[i]=LOW[i]=bel[i]=vis[i]=in[i]=0;}cnt=tot=id=index=0; } int main() {int t,iCase=0;cin>>t;while(t--) {scanf("%d",&n);init();for(int i = 1; i <= n; i++) scanf("%lld%lld%lld%lld", &p[i].x, &p[i].y, &p[i].r, &p[i].c);for(int i = 1; i <= n; i++) {for(int j = 1; j <= n; j++) {if(i == j) continue;if(ok(i, j)) add(i, j);}}for(int i = 1; i <= n; i++) if(!DFN[i]) Tarjan(i); for(int i = 1; i<=n; i++) {for(int j = head[i]; j!=-1; j = e[j].ne) {int u = i,v = e[j].to;if(bel[u]!=bel[v]) {in[bel[v]]++;}}}ll ans = 0;for(int i = 1; i<=cnt; i++) {if(in[i]!=0) continue;ll minn = 0x3f3f3f3f;for(int j = 1; j<=n; j++) {if(bel[j] == i) {minn = min(minn,p[j].c);}}ans += minn;}printf("Case #%d: %d\n", ++iCase, ans);}return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5934】Bomb (强连通分量Tarjan + 缩点)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。