当前位置:网站首页>4273. 链表合并
4273. 链表合并
2022-06-22 00:04:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
文章目录
4273. 链表合并
题意
见原题
思路
翻转较短的链表后,挨个插入即可
代码
/* * @Author: NEFU AB-IN * @Date: 2022-06-20 21:45:36 * @FilePath: \ACM\Acwing\4273.cpp * @LastEditTime: 2022-06-20 22:12:55 */ #include <bits/stdc++.h> using namespace std; #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 << endl; typedef pair<int, int> PII; const int N = 1e6 + 10; int e[N], ne[N]; signed main() { int h1, h2, n; cin >> h1 >> h2 >> n; for (int i = 1; i <= n; ++i) { int addr, d, nxt; cin >> addr >> d >> nxt; e[addr] = d; ne[addr] = nxt; } // 统计结点 vector<int> v1, v2; for (int i = h1; ~i; i = ne[i]) { v1.push_back(i); } for (int i = h2; ~i; i = ne[i]) { v2.push_back(i); } if (SZ(v1) > SZ(v2)) swap(v1, v2); vector<int> ans; reverse(v1.begin(), v1.end()); for (int i = 0, j = 0; i < SZ(v2); ++i) { ans.push_back(v2[i]); if (i & 1 && j < SZ(v1)) ans.push_back(v1[j++]); } for (int i = 0; i < SZ(ans); ++i) { if (i < SZ(ans) - 1) printf("%05d %d %05d\n", ans[i], e[ans[i]], ans[i + 1]); else printf("%05d %d -1", ans[i], e[ans[i]]); } return 0; }
边栏推荐
- Powershell 函数在数学表达式中的使用
- Meetup03 review: introduction to the new version of linkis and the application practice of DSS
- Tensorflow环境搭建
- pytorch学习07:Broadcast广播——自动扩展
- 安装EasyX-VC2019
- 过孔式导电滑环怎么用
- 2. 两数相加
- eslint:错误
- 编译原理-递归下降子程序法
- The interviewer asked me how the order ID was generated? Is it not MySQL self incrementing primary key?
猜你喜欢

【DailyFresh】课程记录3--商品搜索相关

Emperor Taizong of Tang Dynasty played the "heartbeat mechanism" of microservices to the extreme!

Pytorch learning 11:where and gather

Summary of new MySQL 8.0 features

前加后加探索和函数调用探索

Pytorch learning 03: tensor data types and some operations

Version dynamic | exchangis 1.0.0-rc1 version release

Opérations de bits bits et

Enterprises can improve database security in four ways

Pytorch learning 02: handwritten digit recognition
随机推荐
12 BeautifulSoup类的初始化
在徽商期货开户做期货安全吗?
pytorch学习04:Tensor的创建
导电滑环是如何工作的
Graphical understanding of the article "text classification of Sina News Based on tensorflow+rnn"
eVC4编的程序不能在emulator上运行
[Environmental stepping pit] pycharm reports an error when using QT
[environment stepping on pit] error occurs when uploading files using fastdfs test
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
It took 2 hours to build an Internet of things project, which is worth~
SQL语句——权限管理
Pytorch learning 12: automatic derivation
Is it safe to open an account for futures in Huishang futures?
pytorch学习06:Tensor维度变换
位运算位或
Mendix公司新任CFO Tom Ellison通过领导团队转型推动公司下一阶段高速增长
Acwing game 56
0x00007ffff3d3ecd0 in _IO_vfprintf_internal (s=0x7ffff40b5620 <_IO_2_1_stdout_>
MySQL 8.0 新特性梳理汇总
pytorch学习09:矩阵基本运算