bessie come home
来源:互联网 发布:虚拟机安装mac流畅吗 编辑:程序博客网 时间:2024/06/05 22:50
/*ID: daniel.20LANG: JAVATASK: comehome*/import java.io.*;import java.util.*;class comehome { static BufferedReader reader; static PrintWriter writer; static int k = 100; static int[][] map = new int[k][k]; static int M = 99999999; static int[] dist = new int[k]; static boolean marked[]=new boolean[k]; static boolean visited[] = new boolean[k]; static int source = 'Z'-'A'; public static void initial()throws Exception{ reader = new BufferedReader(new FileReader("comehome.in")); int lines = Integer.parseInt(reader.readLine()); for(int i=0;i<k;++i){ for(int j=0;j<k;++j){ map[i][j] = i==j?0:M; } } for(int i=0;i<lines;++i){ StringTokenizer st = new StringTokenizer(reader.readLine()); char t1 = st.nextToken().charAt(0); char t2 = st.nextToken().charAt(0); int t3 = Integer.parseInt(st.nextToken()); map[t1-'A'][t2-'A'] = map[t1-'A'][t2-'A']<t3?map[t1-'A'][t2-'A']:t3; map[t2-'A'][t1-'A'] = map[t2-'A'][t1-'A']<t3?map[t2-'A'][t1-'A']:t3; } } public static void dijkstra(){ int start = 'Z'-'A'; for(int i=0;i<k;++i){ dist[i] = M; marked[i] = false; } dist[start] = 0; marked[start] = true; for(int i=0;i<k;++i){ int minDist = M; int tmpNode = source; for (int j = 0; j < k; ++j) { if (marked[j]) continue; int t1 = dist[start]; int t2 = dist[j]; int t3 = map[start][j]; if (t1 + t3 < t2) { dist[j] = t1 + t3; } if (dist[j] < minDist) { minDist = dist[j]; tmpNode = j; } } start = tmpNode; marked[start] = true; } } public static void getResult() throws Exception{ int min = 9999999,index = 0; writer = new PrintWriter(new BufferedWriter(new FileWriter("comehome.out"))); for (int i = 0; i <= 26; ++i) { if(dist[i]==M||i==source) continue; if(dist[i]<min){ min = dist[i]; index = i; } } writer.print((char)(index+'A')); writer.println(" "+min); writer.close(); System.out.println(min); } public static void print(){ for(int i=0;i<k;++i){ System.out.print(dist[i]+" "); for(int j=0;j<k;++j){ //System.out.print(map[i][j]+" "); } System.out.println(); } } public static void main (String [] args) throws Exception { initial(); dijkstra();// print(); getResult(); //out.close(); System.exit(0); }}
simple dijkstra or floyd...
- [usaco]Bessie Come Home
- bessie come home
- usaco Bessie Come Home
- Bessie Come Home
- USACO:Bessie Come Home
- USACO-Bessie Come Home
- Bessie Come Home
- UVA Bessie Come Home
- USACO Bessie Come Home
- 回家 Bessie Come Home
- 【图论】【USACO】Bessie Come Home
- USACO--2.4Bessie Come Home
- usaco 2.4 bessie come home
- usaco2.4.4 Bessie Come Home
- USACO:Bessie Come Home解题报告
- USACO / Bessie Come Home( Dijkstra标程 )
- USACO 2.4.4 Bessie Come Home
- USACO 2.4 Bessie Come Home (comehome)
- 汉字转换成拼音和获取汉字的首字母及ASSCI码的转换
- Protocol delegate
- Flash游戏开发性能优化
- 动态获取一个服务端控件的客户端ID
- python中最后一个基础知识点,面向对象
- bessie come home
- Android activity属性设置大全
- 关于RMAN recover 过程的讨论
- Android-Adapter应用总结
- RMAN backup recovery area 命令
- 魔方
- Javascript Object学习笔记
- CETK环境搭建及说明
- 13个球一个天平,现知道只有一个和其它的重量不同,问怎样称才能用三次就找到那个球?