因为题目给了边的信息,所以比较适用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. Brush Mode --- Nyoj 236 分类: Brush Mode 2014-04-02 06:56 116人阅读 评论(0) 收藏

    心急的C小加 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间 ...

  2. Centos最小化安装后联网配置

    Centos最小化安装默认不开启网络,只需进行简单配置就可以上网了. 1.  查看/etc/sysconfig/network-scripts/下面的文件,这里会有一个ifcfg-en******(这 ...

  3. [百度空间] [原] 全局operator delete重载到DLL

    由于很久没有搞内存管理了,很多细节都忘记了今天项目要用到operator delete重载到DLL,发现了问题,网上搜索以后,再对比以前写的代码,发现了问题:原来MSVC默认的operator new ...

  4. Codeforces Round #271 (Div. 2) F ,E, D, C, B, A

    前言:最近被线段树+简单递推DP虐的体无完肤!真是弱! A:简单题,照着模拟就可以,题目还特意说不用处理边界 B:二分查找即可,用lower_lound()函数很好用 #include<stri ...

  5. Codeforces Round #266 (Div. 2) D

    D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. BZOJ 3155: Preprefix sum

    大意:给一个数组,先求出SUM[I],然后动态的求出1-I的SUM[I]的和, 这题得化公式: 树状数组维护两个和:SUM(A[I])(1<=I<=X); SUM(A[I]*(N-I+1) ...

  7. javascript实现数据结构与算法系列:循环链表与双向链表

    循环链表(circular linked list) 是另一种形式的链式存储结构.它的特点是表中最后一个结点的指针域指向头结点,整个表形成一个环. 循环链表的操作和线性链表基本一致,仅有细微差别. w ...

  8. 如何修正导入模型的旋转? How do I fix the rotation of an imported model?

    原地址:http://game.ceeger.com/Manual/HOWTO-FixZAxisIsUp.html Some 3D art packages export their models s ...

  9. MYSQL注入天书之order by后的injection

    Background-9  order by后的injection 此处应介绍order by后的注入以及limit注入,我们结合less-46更容易讲解,(在less46中详细讲解)所以此处可根据l ...

  10. sshd_config配置 详解

    原文:http://blog.licess.org/sshd_config/ # 1. 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 Port 22 # S ...