当前位置:网站首页>L2-022 rearrange linked list (25 points) linked list operation
L2-022 rearrange linked list (25 points) linked list operation
2022-04-23 00:36:00 【hys__ handsome】
Topic details - L2-022 Rearrange the list (25 branch ) (pintia.cn)
Ideas : First, generate a linked list through an array , And then through vector Just control the relationship between before and after .
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int N = 100010;
int e[N],ne[N];
int main(){
int n,h;
cin>>h>>n;
memset(ne,-1,sizeof ne);
for(int i = 0; i < n; i++){
int a,b,c;
cin>>a>>b>>c;
e[a] = b;
ne[a] = c;
}
vector<int> ls;
int t = h;
while(t != -1){
ls.push_back(t);
t = ne[t];
}
vector<int> res;
int sz = ls.size();
for(int i = 0; i < sz/2; i++){
res.push_back(ls[sz-1-i]);
res.push_back(ls[i]);
}
if(res.size() < sz) res.push_back(ls[sz/2]);
for(int i = 0; i < res.size(); i++){
printf("%05d %d ",res[i],e[res[i]]);
if(i != res.size()-1) printf("%05d\n",res[i+1]);
else puts("-1");
}
return 0;
}
版权声明
本文为[hys__ handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230033479371.html
边栏推荐
- ArcGIS urban living area land suitability evaluation (III)
- L2-021 点赞狂魔 (25 分)
- ArcGIS urban living area land suitability evaluation (IV)
- ArcGIS 制作3D规划图纸
- L2-007 家庭房产 (25 分) 并查集或图的遍历
- ArcGIS urban living area land suitability evaluation (V)
- C# 11 对 ref 和 struct 的改进
- 396. Rotation function / Sword finger offer II 013 Sum of two-dimensional submatrix
- Bypass network restrictions through RDP tunnel
- Acwing spring daily question - do you know ABC
猜你喜欢

对Indexlookup的理解误区

Xamarin效果第二十二篇之录音效果

C# WPF UI框架MahApps切换主题

js -对连续月份数据做处理拆分

The story of tidb and I met unprepared, but I wanted to say how lucky I was to meet you

Research on swarm intelligence collaborative work and cognitive computing technology

2.57 - Programming show_ short, show_ Long and show_ Double, which print the byte representation of C language objects of types short, long and double respectively. Please try running on several machi

Openresty installation and introduction

Misunderstanding of indexlookup

【图像分类】用最简短的代码复现SeNet,小白一定要收藏(keras,Tensorflow2.x)
随机推荐
MP2459被完美替代内部集成有功率MOSFET管FS2459的60V0.5A降压IC
2.55 - use show on different machines you can access_ Bytes (file show_bytes. C) compile and run the sample code. Determine the byte order used by these machines.
Application of tidb in massive transactions and real-time analysis of fast food chain enterprises
Static and dynamic control nixie tube
在Google工作的十年,也是我开心的十年
Pain points solved by tidb under the wave of localization
The addition inverse element (a ^ a = 0) XOR operation, which has no performance advantage, is just an intelligence game
Process comma separated strings and sort the output in ascending dictionary order
(to) excel 2016 does not have enough memory or disk space to open excel
According to this effective method, UI automation testing is so simple
24V~48V磁吸轨道灯FS2459替代MP2459方案
Differences of lake water color, water environment and hydrological remote sensing
一场由TiCDC异常引发的GC不干活导致的Tikv硬盘使用问题
植被物候參數遙感研究進展(好文分享)
BUUCTF 穿越时空的思念
Alternative scheme of 24V ~ 48V magnetic absorption track lamp fs2459 to mp2459
Network cable IP configuration
Ads communication between two CX controllers of Beifu TwinCAT
[image classification] reproduce senet with the shortest code. Xiaobai must be collected (keras, tensorflow2. X)
C# 11 对 ref 和 struct 的改进