因为题目给了边的信息,所以比较适用bell-man的方法

 /*
 ID: yingzho1
 LANG: C++
 TASK: comehome
 */
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <map>
 #include <vector>
 #include <set>
 #include <algorithm>
 #include <stdio.h>
 #include <queue>
 #include <cstring>
 #include <cmath>
 #include <list>

 using namespace std;
 #define inf 10000000

 ifstream fin("comehome.in");
 ofstream fout("comehome.out");

 int N;
 struct edge {
     char s, d;
     int e;
     edge(int a, int b, int c) : s(a), d(b), e(c) { }
     edge() : s(), d(), e() { }
 };
 map<char, int> dis;
 ;

 int main()
 {
     fin >> N;
     vector<edge> path(*N);

     ; i < N; i++) {
         char s, d;
         int e;
         fin >> s >> d >> e;
         path[edgenum].s = s;
         path[edgenum].d = d;
         path[edgenum++].e = e;
         path[edgenum].s = d;
         path[edgenum].d = s;
         path[edgenum++].e = e;
     }
     //for (int i = 0; i < edgenum; i++) {
         //cout << "s: " << path[i].s << ", d: " << path[i].d << ", e: " << path[i].e << endl;
     //}
     for (char i = 'a'; i <= 'z'; i++) dis[i] = inf;
     for (char i = 'A'; i <= 'Z'; i++) dis[i] = inf;
     dis[;
     bool flag;
     ; i < edgenum; i++) {
         flag = false;
         ; j < edgenum; j++) {
             if (dis[path[j].d] > dis[path[j].s]+path[j].e) {
                 dis[path[j].d] = dis[path[j].s]+path[j].e;
                 flag = true;
                 //cout << "dis[" << path[j].d << "]: " << dis[path[j].d] << endl;
             }
         }
         if (!flag) break;
     }
     int min_path = inf;
     char min_index;
     ; i < edgenum; i++) {
         if (path[i].s >= 'A' && path[i].s < 'Z' && min_path > dis[path[i].s]) {
             min_path = min(min_path, dis[path[i].s]);
             //cout << path[i].s << "'s dis: " << dis[path[i].s] << endl;
             min_index = path[i].s;
         }
     }
     fout <<  min_index << " " << min_path << endl;

     ;
 }

USACO Section 2.4: Bessie Come Home的更多相关文章

  1. USACO Section 2.4 回家 Bessie Come Home

    题目描述 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只最快的母牛). 在挤奶 ...

  2. USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)

    usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...

  3. USACO Section 3.3: Riding the Fences

    典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...

  4. USACO Section 4.2 Drainage Ditches(最大流)

    最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...

  5. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  6. [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)

    nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...

  7. USACO Section 5.3 Big Barn(dp)

    USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1  (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...

  8. USACO Section 1.3 Prime Cryptarithm 解题报告

    题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...

  9. USACO Section 1.1 Your Ride Is Here 解题报告

    题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...

随机推荐

  1. 【转】oracle查询不到表的问题

    ORACLE的问题解决:Ora-00942:表或视图不存在 分类: 数据库2006-07-05 00:15 10793人阅读 评论(4) 收藏 举报 oraclesqlmanager 由powerde ...

  2. Socket 一对多通信

    服务器(TCPServer.java): package visec; import java.net.*; import java.io.*; public class TCPServer{ pub ...

  3. Google Guava学习笔记——简介

    Google Guava是什么东西?首先要追溯到2007年的“Google Collections Library”项目,它提供对Java 集合操作的工具类.后来Guava被进化为Java程序员开发必 ...

  4. 阿里云centos配置ftp和svn全过程

    1.下载xshell 2.登录centos 3.安装vsftpd [root@xxx]# yum install vsftpd //安装vsftpd [root@xxx]# chkconfig vsf ...

  5. 【JQuery NoviceToNinja系列】01 开篇 Html页面设计和布局

    01 开篇 Html页面设计和布局 index.html <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml ...

  6. ios后台下载

    http://www.cocoachina.com/industry/20131106/7304.html

  7. SQLserver分页查询实例

    Sqlserver数据库分页查询一直是Sqlserver的短板,闲来无事,想出几种方法,假设有表ARTICLE,字段ID.YEAR...(其他省略),数据53210条(客户真实数据,量不大),分页查询 ...

  8. APM 终端用户体验监控分析(上)

    一.前言 理解用户体验是从终端用户角度了解应用交付质量的关键,这是考量业务健康运转的潜在因素.捕获此类数据的方法各种各样,具体的实现途径由应用.基础设施架构以及管理者和管理过程决定. 二.终端用户监控 ...

  9. DevExpress TreeList 那些事儿

    1:TreeList绑定数据源 当我们给予TreeList 的 parentFieldName 和 KeyFieldName 两个属性之后 会自动的生成树结构. 1 var sql = @" ...

  10. mysql 存储过程事务支持回滚

    如图查看表的属性: InnoDB 支持事务. MyISAM 不支持事务,不过性能更优越.