当前位置:网站首页>693. 行程排序
693. 行程排序
2022-08-05 06:42:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
693. 行程排序
题意
玛丽需要从某地飞往另一目的地,由于没有直达飞机,所以需要在中途转很多航班。
例如:SFO -> DFW DFW -> JFK JFK -> MIA MIA -> ORD。
显然旅途中不可能到同一中转城市两次或以上,因为这没有意义。
不幸的是,她将自己的机票的顺序搞乱了,将机票按乘坐顺序整理好对她来说不是一件容易的事。
请你帮助玛丽整理机票,使机票按正确顺序排列。思路
哈希,链表输出即可
代码
/* * @Author: NEFU AB-IN * @Date: 2022-08-04 16:35:04 * @FilePath: \Acwing\693\693.cpp * @LastEditTime: 2022-08-04 16:42:55 */ #include <bits/stdc++.h> using namespace std; #define int long long #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define DEBUG(X) cout << #X << ": " << X << '\n' typedef pair<int, int> PII; const int INF = INT_MAX; const int N = 1e6 + 10; signed main() { IOS; int T; cin >> T; for (int _ = 1; _ <= T; ++_) { int n; cin >> n; map<string, string> st; map<string, int> deg; set<string> se; for (int i = 1; i <= n; ++i) { string s, t; cin >> s >> t; st[s] = t; deg[t]++; se.insert(s), se.insert(t); } string s; for (auto c : se) { if (!deg[c]) s = c; } printf("Case #%lld: ", _); while (st.count(s)) { printf("%s-%s ", s.c_str(), st[s].c_str()); s = st[s]; } puts(""); } return 0; }
边栏推荐
- 小程序input框不允许输入负数
- 基于KECA-IGWO-KELM的间歇过程故障诊断方法
- 工作3年,回想刚入门和现在的今昔对比,笑谈一下自己的测试生涯
- After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
- MAYA船的建模
- 【C语言】结构体变量数据通过 void* 传入到函数中
- (四)旋转物体检测数据roLabelImg转DOTA格式
- IO process thread -> communication between processes -> day7
- Rapid Medical's Ultra-Small and Only Adjustable Thromb Retriever Receives FDA Clearance
- typescript65-映射类型(keyof)
猜你喜欢

Week 8 Document Clustering

MySQL:order by排序查询,group by分组查询

typescript65-映射类型(keyof)

数据库多表关联插入数据

Week 8 Document Clustering(文本聚类)

Japan Sanitary Equipment Industry Association: Japan's warm water shower toilet seat shipments reached 100 million sets

400 times performance improvement 丨 swap valuation optimization case calculation

Tencent Internship Summary

二叉搜索树问题

AI+视频技术助力保障校园安全,校园智能安防平台该如何建设?
随机推荐
UDP broadcast
FPGA解析B码----连载4
对数据类型而言运算符无效。运算符为 add,类型为 text。
二叉搜索树问题
Advanced Redis
【网友真实投稿】为女友放弃国企舒适圈,转行软件测试12k*13薪
17-VMware Horizon 2203 virtual desktop-Win10 manual desktop pool floating (seventeen)
PCI Pharma Services Announces Multi-Million Dollar Expansion of UK Manufacturing Facility to Meet Growing Demand for Global High Potency Drug Manufacturing Services to Support Oncology Treatment
【Dynamic type detection Objective-C】
HR:这样的简历我只看了5秒就扔了,软件测试简历模板想要的进。
RNote108---Display the running progress of the R program
2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams
RK3568环境安装
Japan Sanitary Equipment Industry Association: Japan's warm water shower toilet seat shipments reached 100 million sets
技术分析模式(九)三重顶部和底部
MySQL:JDBC编程
Technical Analysis Patterns (11) How to Trade Head and Shoulders Patterns
MySQL: basic part
#Sealos#使用工具部署kubernetesV1.24.0
开启防火墙iptable规则后,系统网络变慢