当前位置:网站首页>1161 Merging Linked Lists
1161 Merging Linked Lists
2022-06-23 05:28:00 【花落的那一天】
题意
给了两个链表,找到最短的,然后插入长的那个里面,长的每隔两个插一个短的,长的长度肯定是短的二倍以上。
Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
const int N = 1e6;
struct node
{
int add;
int data;
int ne;
}node[N];
int main()
{
int L1, L2, n;
cin >> L1 >> L2 >> n;
for (int i = 1; i <= n; i++)
{
int a, b, c;
cin >> a >> b >> c;
node[a] = {
a, b, c};
}
vector<int> l1, l2;
int t = L1;
while (t != -1)
{
l1.push_back(t);
t = node[t].ne;
}
t = L2;
while (t != -1)
{
l2.push_back(t);
t = node[t].ne;
}
if (l1.size() < l2.size()) l1.swap(l2);
reverse(l2.begin(), l2.end());
// for (int i = 0; i < l1.size(); i++) cout << l1[i] << endl;
vector<int> res;
int cnt = 0;
for (int i = 0, j = 0; i < l1.size(); i++)
{
cnt++;
res.push_back(l1[i]);
if (cnt == 2 && j < l2.size())
{
res.push_back(l2[j++]);
cnt = 0;
}
}
for (int i = 0; i < res.size(); i++)
{
if (i + 1 == res.size())
{
cout << setw(5) << setfill('0') << node[res[i]].add << ' ' << node[res[i]].data << ' ' << -1 << endl;
}
else
{
cout << setw(5) << setfill('0') << node[res[i]].add << ' ' << node[res[i]].data << ' ' << setw(5) << setfill('0') << node[res[i + 1]].add << endl;
}
}
return 0;
}
边栏推荐
- 图解 Google V8 # 18 :异步编程(一):V8是如何实现微任务的?
- 如何查看本机IP
- Docker实战 -- 部署Redis集群与部署微服务项目
- Set tensorflow1 X to pytorch
- Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
- 30 data visualization tips that can not be ignored
- MySQL ON DUPLICATE KEY 和 PgSQL ON CONFLICT(主键) 处理主键冲突
- 项目_过滤器Filter解决中文乱码
- Vs+qt project transferred to QT Creator
- English语法_副词 - ever / once
猜你喜欢

Index - MySQL

Day_ 04 smart health project - appointment management - package management

什么是客户体验自动化?

原址 交换

qt creater搭建osgearth环境(osgQT MSVC2017)

Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control

光谱共焦的测量原理及厚度测量模式

QT中的item views与Item widgets控件的用法总结

设计师需要懂的数据指标与数据分析模型

C# wpf 通过绑定实现控件动态加载
随机推荐
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
Haas506 2.0 development tutorial -sntp (only versions above 2.2 are supported)
Day_ 10 smart health project - permission control, graphic report
Haas506 2.0 development tutorial -hota (only supports versions above 2.2)
数值计算方法 Chapter7. 计算矩阵的特征值和特征向量
Machine learning artifact scikit learn minimalist tutorial
Golang regular regexp package use -04- use regular replacement (replaceall(), replaceallliteral(), replaceallfunc())
MySQL5.6 (5.7-8) 基于shardingsphere5.1.1 Sharding-Proxy模式读写分离
mysql如何将日期转为数字
解读创客教育中的团结协作精神
bootstrap如何清除浮动的样式
Smart port: how to realize intelligent port supervision based on the national standard gb28181 protocol easygbs?
图解 Google V8 # 18 :异步编程(一):V8是如何实现微任务的?
A review: neural oscillation and brain stimulation in Alzheimer's disease
Day_ 01 smart communication health project - project overview and environmental construction
MySQL ON DUPLICATE KEY 和 PgSQL ON CONFLICT(主键) 处理主键冲突
2.17 haas506 2.0开发教程-system(仅支持2.2以上版本)
minio单节点部署 minio分布式部署 傻瓜式部署过程 (一)
【系统】右键桌面图标,转圈后,资源管理器就崩溃,桌面就重新刷新
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)