布线问题

时间限制:1000 ms  |  内存限制:65535 KB
难度:4
 
描述
南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:
1、把所有的楼都供上电。
2、所用电线花费最少
 
输入
第一行是一个整数n表示有n组测试数据。(n<5)
每组测试数据的第一行是两个整数v,e.
v表示学校里楼的总个数(v<=500)
随后的e行里,每行有三个整数a,b,c表示a与b之间如果建铺设线路花费为c(c<=100)。(哪两栋楼间如果没有指明花费,则表示这两栋楼直接连通需要费用太大或者不可能连通)
随后的1行里,有v个整数,其中第i个数表示从第i号楼接线到外界供电设施所需要的费用。( 0<e<v*(v-1)/2 )
(楼的编号从1开始),由于安全问题,只能选择一个楼连接到外界供电设备。
数据保证至少存在一种方案满足要求。
输出
每组测试数据输出一个正整数,表示铺设满足校长要求的线路的最小花费。
样例输入
1
4 6
1 2 10
2 3 10
3 1 10
1 4 1
2 4 1
3 4 1
1 3 5 6
样例输出
4

题解:只能选择一个楼连接到外界供电设备。刚开始没看到这句话,错了;

代码:
 #include<stdio.h>
#include<string.h>
const int MAXN=;
#define MIN(x,y)(x<y?x:y)
const int INF=0x3f3f3f3f;
int map[MAXN][MAXN];
int low[MAXN],vis[MAXN];
int ans;
int out[MAXN];
//int usd[MAXN];
int N;
void prim(){
memset(vis,,sizeof(vis));
// memset(usd,0,sizeof(usd));
vis[]=;
for(int i=;i<=N;i++)low[i]=map[][i];
for(int i=;i<=N;i++){
int temp=INF,k;
for(int j=;j<=N;j++)
if(!vis[j]&&low[j]<temp)temp=low[k=j];
if(temp==INF)break;
//if(out[k]<temp)ans+=out[k],usd[k]=1;
//else
ans+=temp;
vis[k]=;
for(int j=;j<=N;j++)
low[j]=MIN(low[j],map[k][j]);
}int temp=INF;
for(int i=;i<=N;i++){
//if(usd[i])continue;
temp=MIN(temp,out[i]);
}
//if(temp==INF)temp=0;
printf("%d\n",ans+temp);
}
int main(){
int n,e,a,b,c;
scanf("%d",&n);
while(n--){
ans=;
memset(map,INF,sizeof(map));
scanf("%d%d",&N,&e);
while(e--){
scanf("%d%d%d",&a,&b,&c);
if(c<map[a][b])map[a][b]=map[b][a]=c;
}
for(int i=;i<=N;i++)scanf("%d",&out[i]);
prim();
}
return ;
}

布线问题(prime)的更多相关文章

  1. nyoj 38 布线问题 Kruskal and Prim

    布线问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件: 1.把所有的 ...

  2. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  3. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  4. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  5. UVa 524 Prime Ring Problem(回溯法)

    传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...

  6. 电子线路 PCB 中大电流 接口 和 布线问题;

    问题1:电流 大小 和 PCB 中 布线线宽的 关系,电源和信号 稳定性? 问题2:大电流中 接口问题,如microUSB 充电接口中,2A等 快充时接口 会 发热,如果 接口的 布线 太细和 不妥善 ...

  7. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  8. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

  9. 最小生成树 prime zoj1586

    题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i ...

随机推荐

  1. 05-3. 求a的连续和(15)

    输入两个整数a和n,a的范围是[0,9],n的范围是[1,8],求数列之和S = a+aa+aaa+...+aaa...a(n个a). 如a为2.n为8时输出的是2+22+222+...+222222 ...

  2. Visual Studio Code和Docker开发asp.net core和mysql应用

    Visual Studio Code和Docker开发asp.net core和mysql应用 .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对 ...

  3. linux查看网卡吞吐量和网卡流量用自带命令,iptraf查看。

    1 命令行直接输入:iptraf(如果没有,使用yum install iptraf安装) 2.打开进入选择ip镜像. 3. 选择监听测试的接口,所有接口. 4.开启监听状态日志,系统默认日志路径./ ...

  4. java比较器 之compareable 和comparato比较

    compareable 测试类import java.util.Set; import java.util.TreeSet; public class Test { public static voi ...

  5. jsonarray----->list

    JSONArray--------------->List----------------->Adapter------------------>ListView

  6. opennebula extend(expending) auth module ldap

    LDAP Authentication addon permits users to have the same credentials as in LDAP, so effectively cent ...

  7. UVA 10003 Cutting Sticks 切木棍 dp

    题意:把一根木棍按给定的n个点切下去,每次切的花费为切的那段木棍的长度,求最小花费. 这题出在dp入门这边,但是我看完题后有强烈的既是感,这不是以前做过的石子合并的题目变形吗? 题目其实就是把n+1根 ...

  8. express4.0之后不会解析req.files,必须加一个插件multer

    express 4 + 用multer express4.0之后不会解析req.files,必须加一个插件multer http://www.w3school.com.cn/tags/att_form ...

  9. wx.Dialog

    wx.Dialog A dialog box is a window with a title bar and sometimes a system menu, which can be moved ...

  10. 在CGridView调用CJuiDialog的弹出层

    <?php $this->widget('zii.widgets.grid.CGridView', array(    'id'=>'user-grid',    'dataProv ...