因为题目给了边的信息,所以比较适用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. Excel插件类库的设计思路

    一.插件功能:提供多种读取Excel的方式,如NPOI.Com.Aspose,调用接口一致,包括Excel文件路径,sheet名称.读取是否包含列头(即Excel第一行是否为列头行) 二.实现思路 2 ...

  2. java socket 一个服务器对应多个客户端,可以互相发送消息

    直接上代码,这是网上找的demo,然后自己根据需求做了一定的修改.代码可以直接运行 服务器端: package socket; import java.io.BufferedReader; impor ...

  3. SQL SERVER 导出到Oracle 问题与技巧

    工具: 使用SQL SERVER自带的导入, 导出工具   技巧: 一. 使用Oracle Provider for OLE DB(强制推荐) 1. 速度快 2. 要安装Oracle驱动(Oracle ...

  4. Environment.SpecialFolder.CommonApplicationData

    private void button1_Click(object sender, EventArgs e) { var path=Environment.GetFolderPath(Environm ...

  5. https+ssl详解

    这是转载别人的写的很好,(转:崔永秀) 把这几天学习到的关于ssl和https协议的内容在这里分享一下,适合一些像我一样的网络协议初学者. ssl协议的起源和历史我就不再多说了,就是那个Netscap ...

  6. js中的null VS undefined

    var a;------>undefined. JS变量的默认值.注意点在于判断变量的值为null.这是错误的.比如 if( a === null ) { // TODO; }; 实际上是und ...

  7. Web流程

    Web阻塞加载,异步加载. 延迟执行,立即执行. 加载并执行,不要调用代码. 加载并执行时会调用代码,但是加载并执行时不要调用代码,否则会改变逻辑. 上面是Web流程,JS只是web的一部分.如果关注 ...

  8. nodeJs入门篇之认识nodejs

    摘要:将介绍如何利Javascript做为服务端脚本,通过Nodejs框架web开发.Nodejs框架是基于V8的引擎,是目前速度最快的Javascript引擎.chrome浏览器就基于V8,同时打开 ...

  9. Python:Python 3.x 的革新

    Python 3.x 版本在设计时为了向最好的语言前进,没有考虑向下兼容,许多针对早期 Python 版本设计的程序都无法正常运行.本文简单介绍了 Python 3.x 版本较之 2.x 版本语法上的 ...

  10. response ,request编码

    request.setCharacterEncoding()是你设置获得数据的编码方式.response.setCharacterEncoding()是你响应时设置的编码.response.setCo ...