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求余数. 题目给你两个字符串,其中的字 ...
随机推荐
- 【Merge Two Sorted Lists】cpp
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- Java/Java Web中乱码解决汇总
在开发Java/Java Web Application过程中,往往会出现乱码问题,而且有的时候真会弄得人很烦,浪费太多的时间. 记得之前看过一篇帖子,详细解释了Encoding/Decoding过程 ...
- 来自平时工作中的css知识的积累---持续补充中
① 现代浏览器中,<img>元素默认情况下底部会有空白,那么这个空白到底是从哪里来的? 解惑: method-one:猛戳 来自知乎的解答 method-two: 延伸阅读 what is ...
- 引擎设计跟踪(九.14.2h) 开发计划
以后的开发计划: 完善game runtime code, 跑简单的demo目前只有编辑器的运行流程, 没有游戏/demo流程, 图形的测试主要在编辑器上测试, 现在需要测试android系统的图形, ...
- 深入理解python之self
首先明确的是self只有在类的方法中才会有,独立的函数或方法是不必带有self的.self在定义类的方法时是必须有的,虽然在调用时不必传入相应的参数. self名称不是必须的,在python中self ...
- 说说Thread.Sleep(0)的那些奇怪的事
写在前面 最近在弄一个传输组件,用到很多多线程的知识,其中有个问题,困扰我很久,不知道是什么原因,脑子一热,在传输过程中,添加了一句代码Thread.Sleep(0).那个问题竟然解决了,耗费我一上午 ...
- maven mirror repository
简单点来说,repository就是个仓库.maven里有两种仓库,本地仓库和远程仓库.远程仓库相当于公共的仓库,大家都能看到.本地仓库是你本地的一个山寨版,只有你看的到,主要起缓存作用.当你向仓库请 ...
- Sqli-labs less 28
Less-28 本关考察内容与27关没有太大的差距,我们直接给出一个payload: http://127.0.0.1/sqllib/Less-28/?id=100')union%a0select(1 ...
- 总结 | 如何测试你自己的 RubyGem
如何测试一个Gem gem 开发完了,想要给别人用,那就需要测试啊,测试一个 gem 其实很简单,这里我们用 minitest 为例, rspec 也一样适用.先来看看我们当前这个 gem 的目录结构 ...
- HDU 2671 Can't be easier(数学题,点关于直线对称)
题目 //数学题//直线 y = k * x + b//直线 ax+by+c=0; 点 (x0,y0); 点到直线距离 d = (ax0+by0+c)/sqrt(a^2+b^2) /********* ...