当前位置:网站首页>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;
}
边栏推荐
- ffplay实现自定义输入流播放
- Haas506 2.0 development tutorial -sntp (only versions above 2.2 are supported)
- 解析创客教育中的造物原理
- Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
- 将TensorFlow1.x改写为pytorch
- 光谱共焦的测量原理及厚度测量模式
- Sklearn classification in sklearn_ Report & accuracy / recall /f1 value
- 聚焦智慧城市,华为携手中科星图共同开拓数字化新蓝海
- C# wpf 附加属性实现界面上定义装饰器
- Softing dataFEED OPC Suite将西门子PLC数据存储到Oracle数据库中
猜你喜欢

QT creator builds osgearth environment (osgqt msvc2017)

CPU的功能和基本结构

Network architecture from Wan to sd-wan edge devices

业务逻辑安全思路总结

Synchronous switching power supply reduces EMI layout dv/dt di/dt

Day_ 02 smart communication health project - appointment management - inspection item management

解读创客教育中的团结协作精神

Day_ 07 smart communication health project FreeMarker
百度URL參數之LINK?URL參數加密解密研究(代碼實例)

图解 Google V8 # 17:消息队列:V8是怎么实现回调函数的?
随机推荐
Day_ 01 smart communication health project - project overview and environmental construction
开源生态|超实用开源License基础知识扫盲帖(下)
坐标 转化
leetcode - 572. 另一棵树的子树
Kubesphere offline deployment without network environment
haas506 2.0开发教程-hota(仅支持2.2以上版本)
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)
How to maintain secure encryption of email communication with FDA?
Docker实战 -- 部署Redis集群与部署微服务项目
Skilled use of slicing operations
从 WAN 到 SD-WAN 边缘设备的网络架构
百度URL参数之LINK?URL参数加密解密研究(代码实例)
279.完全平方数
C# wpf 通过绑定实现控件动态加载
了解学习 JSX 的工作方式
Smart port: how to realize intelligent port supervision based on the national standard gb28181 protocol easygbs?
There are so many code comments! I laughed
Laravel log channel grouping configuration
解析创客教育中的造物原理
QT中的item views与Item widgets控件的用法总结