当前位置:网站首页>4273. linked list consolidation
4273. linked list consolidation
2022-06-22 01:13:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
List of articles
4273. List merge
The question
See the original question
Ideas
After flipping the short linked list , Insert one by one
Code
/* * @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; } // Statistical nodes 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; }
边栏推荐
- 【环境踩坑】使用FastDFS测试上传文件时报错
- 面试题目录收集
- pytorch学习10:统计运算
- 【环境踩坑】在自己电脑上搭建FastDFS
- Ns32f103vbt6 hardware and software replace stm32f103vbt6
- 利用SSM框架实现用户登陆
- SQL语句——权限管理
- It took 2 hours to build an Internet of things project, which is worth~
- Pytorch learning 13: implement letnet and learning nn Module related basic operations
- Pat (a) - 1001 a+b format
猜你喜欢
![Chapter VIII exercises (45A) [microcomputer principles] [exercises]](/img/79/8311a409113331e72f650a83351b46.png)
Chapter VIII exercises (45A) [microcomputer principles] [exercises]

pytorch学习04:Tensor的创建

MySQL 8.0 新特性梳理汇总

如何使用物联网低代码平台进行报表管理?

pytorch学习11:where 和 gather

Simple sorting of RNN

Graphical understanding of the article "text classification of Sina News Based on tensorflow+rnn"

安装EasyX-VC2019
![四数之和[数组排序+双指针]](/img/9e/e1932120a9b69847898e89c45e2eb4.png)
四数之和[数组排序+双指针]

【Redis】事件驱动框架源码分析(单线程)
随机推荐
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Status code summary
从简单实例来看 left join 如何去重
Using SSM framework to realize user login
Pytorch learning 07:broadcast broadcast - automatic extension
【环境踩坑】使用FastDFS测试上传文件时报错
【环境踩坑】No module named ‘PyQt5‘
div设置滚动和监听滚动距离
Pytorch learning 05: indexing and slicing
[examination skills] memory method and simple derivation of Green formula
RNN的简单整理
English grammar_ Adverb - loud /aloud / loud
HDOJ - Is It A Tree?
Pytorch learning 11:where and gather
.NET中获得hInstance的几个方法
四数之和[数组排序+双指针]
The importance of rational selection of seal clearance of hydraulic slip ring
MSVC与GCC的差异(收集中)
3746. 牛的学术圈 II
Introduction to redis Series 7 - expiration policy