USACO Section 2.4: Bessie Come Home
2024-08-21 04:36:16
因为题目给了边的信息,所以比较适用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; ; }
最新文章
- hibernate一对一主键单向关联
- 关于网络-get/post
- redis-key2
- 图表控件MsChart使用demo
- python os模块使用方法
- SQL中一种类似GUID值的函数实现
- 网址、URL
- .rdp 文件参数详解
- [LeetCode] 134. Gas Station 解题思路
- HdU 4046 Panda 段树
- 新书发布《每天5分钟玩转Docker容器技术》
- 设计模式复习小结一(Strategy Pattern/Observer Pattern/Decorator Patter/Factory Pattern)
- 最短路径---dijkstra算法模板
- koa-router 源码由浅入深的分析(7.4.0版本的)
- redis操作(String,Hash,List,Set,其他操作)
- 急速安装lnmp 编译版本
- HDU4288-STL模拟
- python实现Telnet远程登陆到设备并执行命令
- rocketMq排坑:如何设置rocketMq broker的ip地址
- 第七篇:几个经典的TCP通信函数
热门文章
- springmvc返回jsp源代码解决办法
- 使用个推的时候出现Installation error: INSTALL_FAILED_DUPLICATE_PERMISSION
- 前端之JavaScript第一天学习(3)-JavaScript输出
- sourceInsight使用技巧,持续更新中~~~
- HDU 5800 To My Girlfriend 背包
- Matlab交集并集的实现
- if in hlsl
- c++ assert
- ActionScript基本语法讲解
- .NET设计模式(9):桥接模式(Bridge Pattern)(转)