当前位置:网站首页>L2-002 linked list weight removal (25 points)
L2-002 linked list weight removal (25 points)
2022-04-23 00:36:00 【hys__ handsome】
Topic details - L2-002 The chain watch is weightless (25 branch ) (pintia.cn)
Ideas : First use the array to build a linked list according to the input , Then judge the weight , Use vector Storage naturally has a context .
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
const int N = 100010;
struct Node{
int k,val;
};
int val[N],ne[N];
vector<Node> res1,res2;
bool book[N];
int main(){
int n,h;
cin>>h>>n;
for(int i = 0; i < n; i++){
int k;
cin>>k;
cin>>val[k]>>ne[k];
}
for(int t = h; t != -1; t = ne[t]){
int v = abs(val[t]);
if(book[v]){
res2.push_back({t,val[t]});
} else {
res1.push_back({t,val[t]});
}
book[v] = true;
}
for(int i = 0; i < res1.size(); i++){
printf("%05d %d ",res1[i].k,res1[i].val);
if(i != res1.size()-1) printf("%05d\n",res1[i+1].k);
else printf("-1\n");
}
for(int i = 0; i < res2.size(); i++){
printf("%05d %d ",res2[i].k,res2[i].val);
if(i != res2.size()-1) printf("%05d\n",res2[i+1].k);
else printf("-1\n");
}
return 0;
}
Practice two :L2-002 The chain watch is weightless (25 branch )_tsuiraku The blog of -CSDN Blog
版权声明
本文为[hys__ handsome]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230033479535.html
边栏推荐
- js -对连续月份数据做处理拆分
- 396. Rotation function / Sword finger offer II 013 Sum of two-dimensional submatrix
- MySQL -- operation of database
- Usage of while (n -- > 0)
- (to) excel 2016 does not have enough memory or disk space to open excel
- Migrate AWS S3 data to tidb cloud cluster
- ArcGIS urban living area land suitability evaluation (IV)
- ArcMap spatial connection and intersection tool
- Network cable IP configuration
- repeat_ String delete some characters
猜你喜欢

ArcGIS 城市生活区用地适宜性评价(一)

Usage of while (n -- > 0)

Bypass network restrictions through RDP tunnel

将 AWS S3 数据迁移至 TiDB Cloud 集群

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

Detailed introduction of Mitsubishi mr-je-c servo application

A tikv hard disk usage problem caused by GC not working caused by ticdc exception

ArcGIS 计算地块容积率

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

JVM performance tuning 1
随机推荐
智能无线传输模组,CV5200助力无人机mesh组网,无线通信传输方案
国产化浪潮下TiDB解决的痛点问题
深度学习基础学习-残差
ArcMap spatial connection and intersection tool
Research Progress on remote sensing of vegetation phenological parameters (good article sharing)
Generation and mutual conversion of ArcGIS tin ground surface and grid ground surface
MP2459被完美替代内部集成有功率MOSFET管FS2459的60V0.5A降压IC
ArcGIS 制作3D遥感影像图
命令行修改电脑IP
2.58 - write the program is little endian, which returns 1 when compiled and run on the small end method machine and 0 when compiled and run on the large end method machine. This program should be abl
L3-1 直捣黄龙 (30 分) djk+dfs
Research progress of Lake remote sensing (Overview)
repeat_ String delete some characters
Differences of lake water color, water environment and hydrological remote sensing
repeat_ dijkstra
js -对连续月份数据做处理拆分
El2521 control module stepper driver
Xamarin效果第二十二篇之录音效果
Buuctf hidden key
Research on swarm intelligence collaborative work and cognitive computing technology