[CCPC杭州] Bomb 强连通分量

来源:互联网 发布:松江3208联动编程软件 编辑:程序博客网 时间:2024/04/27 22:37

Bomb

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1894    Accepted Submission(s): 631


Problem Description
There are N bombs needing exploding.

Each bomb has three attributes: exploding radius ri, position (xi,yi) and lighting-cost ci which means you need to pay ci 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 T, which indicates the number of test cases.

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

In the following N lines, the ith line contains four intergers xiyiri and ci, indicating the coordinate of ith bomb is (xi,yi), exploding radius is ri and lighting-cost is ci.

Limits
1T20
1N1000
108xi,yi,ri108
1ci104
 

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
150 0 1 51 1 1 60 1 1 73 0 2 105 0 1 4
 

Sample Output
Case #1: 15
 

Source
2016年中国大学生程序设计竞赛(杭州)
 

Recommend
liuyiding


先利用强连通分量缩点,这样图就不存在环了,然后再直接引入度为0的点就好


#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1e5;const int INF = 1e9;vector<int> G[maxn];int pre[maxn],lowlink[maxn],sccno[maxn],dfs_clock,scc_cnt;stack<int> S;void dfs(int u){    pre[u] = lowlink[u] = ++dfs_clock;    S.push(u);    for(int i=0;i < G[u].size();i++)    {        int v = G[u][i];        if(!pre[v])        {            dfs(v);            lowlink[u] = min(lowlink[u],lowlink[v]);        }        else if(!sccno[v])        {            lowlink[u] = min(lowlink[u],pre[v]);        }    }    if(lowlink[u] == pre[u])    {        scc_cnt++;        for(;;)        {            int x = S.top();            S.pop();            sccno[x] = scc_cnt;            if(x==u) break;        }    }}void find_scc(int n){    dfs_clock = scc_cnt = 0;    memset(sccno,0,sizeof(sccno));    memset(pre,0,sizeof(pre));    for(int i = 0;i < n;i++)    {        if(!pre[i])        {            dfs(i);        }    }}int n;ll x[1005];ll y[1005];ll r[1005];ll c[1005];ll getdis(int i,int j){    return (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);}ll in[maxn];int T;ll nto[maxn];ll num[maxn];int main(){//    freopen("data.txt","r",stdin);    ios_base::sync_with_stdio(false);    scanf("%d",&T);    int cas=0;    while(T--)    {        cas++;        cout <<"Case #"<<cas<<": ";        scanf("%d",&n);        memset(in,0,sizeof(in));        memset(num,0,sizeof(num));        for(int i=0;i<=n;i++)        {            nto[i]=INF;            G[i].clear();        }        for(int i=0;i<n;i++)        {            scanf("%lld%lld%lld%lld",&x[i],&y[i],&r[i],&c[i]);        }        for(int i=0;i<n;i++)        {            for(int j=0;j<n;j++)            {                if(j==i) continue;                if(r[i]*r[i]>=getdis(i,j))                {//                    cout << i<<"->"<<j<<endl;                    G[i].push_back(j);                }                if(r[j]*r[j]>=getdis(i,j))                {//                    cout << j <<"->"<< i <<endl;                    G[j].push_back(i);                }            }        }        find_scc(n);        for(int i=0;i<n;i++)        {            num[sccno[i]]++;            nto[ sccno[i] ] = min(nto[ sccno[i] ],c[i]);        }        ll ans =0 ;        for(int i=0;i<n;i++)        {            for(int j=0;j<G[i].size();j++)            {                if(sccno[G[i][j]]!=sccno[i])                    in[ sccno[G[i][j]] ]++;            }        }        for(int i=1;i<=scc_cnt;i++)        {            if(in[i]==0)            {                ans += nto[i];            }        }        cout << ans<<endl;    }    return 0;}









原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 美版iphone屏摔了怎么办 天地荣域四十后怎么办 淘宝拍下商品不付款怎么办 淘宝买东西取消订单淘金币怎么办 淘宝淘金币快过期了怎么办 公众号密码忘了怎么办 酷狗直播个入驻粉丝少怎么办 健康证预约显示未接收怎么办 在互惠车贷逾期怎么办 天天中彩票怎么登陆不了怎么办 正宇新商城不能提现怎么办 融e购买完不发货怎么办 婴儿肚子胀气肚脐凸出来怎么办 微信商城买东西被骗了怎么办 拼多多商家不发货怎么办 鞋上的饰品掉了怎么办 饰品上的钻掉了怎么办 dota2饰品被好友礼物怎么办 dota2接收的礼物打不开怎么办 英雄联盟线上被压制怎么办 云联商城的钱怎么办 高顿财经不退款怎么办 拼多多连不上网怎么办 拼多多评分太低怎么办 拼多多限制提现怎么办 手机收不到验证码怎么办 淘宝未发货怎么取消退款怎么办 羊皮的鞋子刮坏怎么办 退货寄错了东西怎么办 毒app上买鞋尺码不合适怎么办 拼多多一直不发货怎么办 天猫国际买东西被税要退货怎么办 国外快递被税了怎么办 手机上传图片时过大怎么办 原网页被重新排版怎么办 文件目录损坏且无法读取怎么办 360木马查杀蓝屏怎么办 电脑上传的文件大小超过限制怎么办 文件最大不超过200m怎么办 抖音上传文件太大怎么办 下载ppt变成php文件怎么办