当前位置:网站首页>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;
}
边栏推荐
- minio单节点部署 minio分布式部署 傻瓜式部署过程 (一)
- How to build a data application system based on overall value for energy enterprises
- Qt 中 QVariant 使用总结
- haas506 2.0开发教程-高级组件库-modem.voiceCall(仅支持2.2以上版本)
- 综合培养学生脑力思维的少儿编程
- 什么是客户体验自动化?
- Haas506 2.0 development tutorial - Advanced Component Library -modem Sim (only supports versions above 2.2)
- 微信小程序 - 全局监听globalData的某个属性变化,例如监听网络状态切换
- Topic35——34. 在排序数组中查找元素的第一个和最后一个位置
- haas506 2.0开发教程-高级组件库-modem.sms(仅支持2.2以上版本)
猜你喜欢
百度URL參數之LINK?URL參數加密解密研究(代碼實例)

二叉树的遍历及相关知识

项目_过滤器Filter解决中文乱码

原址 交换

Gridsearchcv (grid search), a model parameter adjuster in sklearn

QT creator builds osgearth environment (osgqt msvc2017)

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

Day_ 10 smart health project - permission control, graphic report

c#数据库报错问题大家帮我看看吧

【系统】右键桌面图标,转圈后,资源管理器就崩溃,桌面就重新刷新
随机推荐
English语法_副词 - ever / once
坐标 转化
Vs+qt project transferred to QT Creator
c#数据库报错问题大家帮我看看吧
C# wpf 通过绑定实现控件动态加载
Day_ 12 smart health project jasperreports
Linked Storage
I heard you want to embed ppt on WordPress website?
如何实现与FDA保持邮件通信安全加密?
Network architecture from Wan to sd-wan edge devices
Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control
Test of ers function under the supplier consignment purchase mode of SAP mm
Link of Baidu URL Parameters? Recherche sur le chiffrement et le décryptage des paramètres d'URL (exemple de Code)
同步开关电源降低EMI布局 dv/dt di/dt
There are so many code comments! I laughed
Get to know webassembly quickly
Mysql5.6 (5.7-8) is based on shardingsphere5.1.1 sharding proxy mode. Read / write separation
SAP execution transaction code mrrl error -no message was found for partner 100065-
haas506 2.0开发教程-sntp(仅支持2.2以上版本)
百度URL參數之LINK?URL參數加密解密研究(代碼實例)