【杭电2015年12月校赛D】【水题 最小生成树】Happy Value 最小生成树裸题
来源:互联网 发布:河东区中山门淘宝街 编辑:程序博客网 时间:2024/06/06 18:05
Happy Value
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1388 Accepted Submission(s): 408
Problem Description
In an apartment, there are N residents. The Internet Service Provider (ISP) wants to connect these residents with N – 1 cables.
However, the friendships of the residents are different. There is a “Happy Value” indicating the degrees of a pair of residents. The higher “Happy Value” is, the friendlier a pair of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
However, the friendships of the residents are different. There is a “Happy Value” indicating the degrees of a pair of residents. The higher “Happy Value” is, the friendlier a pair of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
Input
There are multiple test cases. Please process to end of file.
For each case, the first line contains only one integer N (2<=N<=100), indicating the number of the residents.
Then N lines follow. Each line contains N integers. Each integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hijwith jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
For each case, the first line contains only one integer N (2<=N<=100), indicating the number of the residents.
Then N lines follow. Each line contains N integers. Each integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hijwith jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
Output
For each case, please output the answer in one line.
Sample Input
20 11 030 1 51 0 35 3 0
Sample Output
18
#include<stdio.h>#include<algorithm>#include<ctype.h>#include<string.h>using namespace std;int casenum,casei;typedef long long LL;const int N=105;const int M=105*105;int n,m;struct A{ int x,y,z; bool operator < (const A& b)const { return z>b.z; }}a[M];int f[N];int find(int x){return f[x]==x?x:f[x]=find(f[x]);}int main(){ while(~scanf("%d",&n)) { m=0; for(int i=1;i<=n;++i) { f[i]=i; for(int j=1;j<=n;++j) { int x; scanf("%d",&x); if(i<j) { ++m; a[m].x=i; a[m].y=j; a[m].z=x; } } } int ans=0; sort(a+1,a+m+1); for(int i=1;i<=m;++i) { int x=find(a[i].x); int y=find(a[i].y); if(x!=y) { ans+=a[i].z; f[y]=x; } } printf("%d\n",ans); } return 0;}/*【题意】就是一个完全图的最小生成树。什么也不说了= = */
0 0
- 【杭电2015年12月校赛D】【水题 最小生成树】Happy Value 最小生成树裸题
- 杭电ACM1162(最小生成树)
- 杭电ACM1233(最小生成树)
- 杭电ACM1863(最小生成树)
- 杭电1879题 最小生成树
- 杭电1233最小生成树kruskal
- 杭电 1863 最小生成数
- 2015’12杭电校赛1004 Happy Value (最大生成树)
- 最小生成树 TOJ 4117 Happy tree friends
- TJU-4117 Happy tree friends(最小生成树)
- 杭电 1233 最小生成树 kruskal()算法
- 杭电 1162 kruskal()算法 最小生成树
- 【最小生成树+Prim】杭电 hdu 1863 畅通工程
- 【最小生成树+kruskal】杭电 hdu 1863 畅通工程
- 【最小生成树+Prim】杭电 hdu 1102 Constructing Roads
- 杭电1162 Eddy's picture 最小生成树
- 杭电1102 Constructing Roads(最小生成树)
- 最小生成树 (基础)杭电1233
- 【后缀数组】[UVA10829]L-Gap substring
- 深入分析JavaWeb Item35 -- 过滤器Filter学习
- Linux下,强制删除oracle10g安装文件后再重装
- Untiy鼠标控制角色转向
- 好奇心害死猫——codevs3123超大整数乘法
- 【杭电2015年12月校赛D】【水题 最小生成树】Happy Value 最小生成树裸题
- ios 字符串大小写转换代码
- TeamTalk部署教程
- Unity调用外部EXE和启动浏览器(手机端也可以启动IE内核)
- 树链剖分
- 【Android Studio】防止切换屏幕方向时webview重新加载url
- 【杭电2015年12月校赛E】【二进制拆分】Bitwise Equations 第K小的X满足X或Y=X+Y
- 韦东山第三期视频监控编译华美路由器A100固件问题----已经编译通过
- Mac OS X上使用Wireshark抓包 (抓取手机网络)