JAVA 结构体sort举例
来源:互联网 发布:网络的负面影响规点 编辑:程序博客网 时间:2024/06/03 17:43
HDU 1865 最小生成树
import java.awt.List;import java.io.BufferedInputStream;import java.util.ArrayList;import java.util.Collections;import java.util.Scanner;public class Main { public static class Node implements Comparable<Node> { int x, y, val; Node(int x, int y, int val) { this.x = x; this.y = y; this.val = val; } @Override public int compareTo(Node o) { // TODO Auto-generated method stub if(val < o.val) return -1; else if(o.val < val) return 1; else return 0; } } static int []fa = new int[110]; public static int find(int x) { if(fa[x] == x) return x; fa[x] = find(fa[x]); return fa[x]; } public static void init(int m) { for(int i = 1; i <= m; ++ i) fa[i] = i; } public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); while(cin.hasNext()) { int n = cin.nextInt(); int m = cin.nextInt(); if(n == 0) break; init(m); ArrayList<Node>list = new ArrayList<Node>(); for(int i = 0; i < n; ++ i) { int x = cin.nextInt(); int y = cin.nextInt(); int val = cin.nextInt(); list.add(new Node(x, y, val)); } Collections.sort(list); long ans = 0; int cnt = 0; for(int i = 0; i < n; ++ i) { int xx = find(list.get(i).x); int yy = find(list.get(i).y); if(xx != yy) { cnt ++; fa[xx] = yy; ans += list.get(i).val; } } if(cnt == m - 1) System.out.println(ans); else System.out.println("?"); } }} /*3 32 3 41 2 11 3 2*/
阅读全文
0 0
- JAVA 结构体sort举例
- 结构体+sort()函数
- 【水题】sort+结构体
- collections.sort()在java程序中的应用举例
- 运动会(sort+结构体+分段sort)
- 结构体排序,sort排序,c++sort
- sort函数妙用举例
- c++ sort()结构体排序
- 结构体、sort的使用
- sort 对结构体排序
- qsort sort 结构体排序
- 结构体sort快速排序
- Milk(sort+结构体)
- hdoj1070Milk(sort+结构体)
- 排名(sort结构体)
- sort对结构体排序
- 【结构体】【sort】多重排序
- 结构体排序,使用sort
- hdu 4825 (01字典树裸题)
- 树莓派配置samba服务器
- net.sf.json.JSONException: java.lang.reflect.InvocationTargetException错误的原因与解决方法?
- 游戏人工智能开发之6种决策方法
- Can't use Subversion command line client:svn
- JAVA 结构体sort举例
- linux下练习正则表达式
- luoguP1437 [HNOI2004]敲砖块(dp)
- 移植libffi到SylixOS
- 添加 排序
- 排jar包的依赖冲突的方法
- Spring Cloud之服务注册与发现Eureka【Dalston.SR4版】
- banner实现无线轮播
- luogu P3088 [USACO13NOV]Crowded Cows