USACO Section 2.4: Bessie Come Home
因为题目给了边的信息,所以比较适用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的更多相关文章
- USACO Section 2.4 回家 Bessie Come Home
题目描述 现在是晚餐时间,而母牛们在外面分散的牧场中. 农民约翰按响了电铃,所以她们开始向谷仓走去. 你的工作是要指出哪只母牛会最先到达谷仓(在给出的测试数据中,总会有且只有一只最快的母牛). 在挤奶 ...
- 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&& ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 4.2 Drainage Ditches(最大流)
最大流问题.ISAP算法.注意可能会有重边,不过我用的数据结构支持重边.距离d我直接初始化为0,也可以用BFS逆向找一次. -------------------------------------- ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- 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 ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
随机推荐
- 如何分离数据库 (SQL Server Management Studio)
在 SQL Server Management Studio 对象资源管理器中,连接到 SQL Server 数据库引擎的实例上,再展开该实例. 展开“数据库”,并选择要分离的用户数据库的名称. 分离 ...
- 设计模式 --深入理解javascript
/* 一.单例模式 */ var Universe; (function () { var instance; Universe = function Universe() { if (instanc ...
- BZOJ 4500: 矩阵 差分约束
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4500 题解: 从行向列建边,代表一个格子a[i][j],对每个顶点的所有操作可以合并在一 ...
- bzoj 2751 快速幂
首先我们知道,对于所有种情况,我们可以将每一位可以放的 数的值加起来,所有位置的乘起来,等于的就是最后的答案,具体 为什么正确,可以根据乘法分配律来想一想. 那么对于所有不做要求的,快速幂直接算就行了 ...
- nsight 使用问题
slot 0 offset 0 stride DXGI_FORMAT_r32b32g32_FLOAT 这样一个memory 100.0000, 100.0000,10.0000,1.0000 stri ...
- 科学家有了钱以后,真是挺吓人的——D.E.Shaw的牛逼人生
科学家有了钱以后,真是挺吓人的——D.E.Shaw的牛逼人生 黑科技,还是要提D.E.Shaw Research这个奇异的存在. 要讲这个黑科技,我们可能要扯远一点,先讲讲D.E. Shaw这个人是怎 ...
- Nodejs Express 4.X 中文API 4--- Router篇
相关阅读: Express 4.X API 翻译[一] -- Application篇 Express4.XApi 翻译[二] -- Request篇 Express4.XApi 翻译[三] -- ...
- 高达渐出现效果Shader
原地址: http://liweizhaolili.blog.163.com/blog/static/1623074420140591864/ 最近在玩游戏<高达破坏者>,里面的高达出现的 ...
- MYSQL注入天书之宽字节注入
Background-7 宽字节注入 Less-32,33,34,35,36,37六关全部是针对'和\的过滤,所以我们放在一起来进行讨论. 对宽字节注入的同学应该对这几关的bypass方式应该比较了解 ...
- 2016年度 JavaScript 展望(下)
[编者按]本文作者为资深 Web 开发者 TJ VanToll, TJ 专注于移动端 Web 应用及其性能,是<jQuery UI 实践> 一书的作者. 本文系 OneAPM 工程师编译呈 ...