当前位置:网站首页>Pat a-1165 block reversing (25 points)
Pat a-1165 block reversing (25 points)
2022-07-02 02:13:00 【White speed Dragon King's review】

subject :
Turn it over as a whole according to a certain length
Ideas :
Definition node Then simulate it
src:
#include<bits/stdc++.h>
using namespace std;
struct node {
int val, next;
}nodeList[100010];
int main() {
int start, n, k;
cin >> start >> n >> k;
for(int i = 0; i < n; i++) {
int index;
cin >> index;
cin >> nodeList[index].val;
cin >> nodeList[index].next;
}
// get the sll
vector<int> v;
int p = start;
while(p != -1) {
v.push_back(p);
p = nodeList[p].next;
}
//cout << v[1] << endl;
int m = v.size();
//int q = m / k;
int r = m % k;
int next = m - r - k;
if(r != 0) {
for(int i = m - r; i < m; i++) {
if(i != m - 1) printf("%05d %d %05d\n", v[i], nodeList[v[i]].val, v[i + 1]);
else printf("%05d %d %05d\n", v[i], nodeList[v[i]].val, v[next]);
}
}
while(next >= 0) {
int now = next;
next -= k;
for(int i = now; i < now + k; i++) {
if(i != now + k - 1) printf("%05d %d %05d\n", v[i], nodeList[v[i]].val, v[i + 1]);
else {
if(next >= 0) printf("%05d %d %05d\n", v[i], nodeList[v[i]].val, v[next]);
else printf("%05d %d -1\n", v[i], nodeList[v[i]].val);
}
}
}
return 0;
}
summary :
It's just a little disgusting , find start Of index Output backward k Just one
边栏推荐
- * and & symbols in C language
- JPM 2021 most popular paper released (with download)
- 【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
- 【带你学c带你飞】2day 第8章 指针(练习8.1 密码开锁)
- As a software testing engineer, will you choose the bank post? Laolao bank test post
- how to add one row in the dataframe?
- [deep learning] Infomap face clustering facecluster
- The middle element and the rightmost element of the shutter
- leetcode2312. Selling wood blocks (difficult, weekly race)
- Summary of some experiences in the process of R & D platform splitting
猜你喜欢

Leetcode face T10 (1-9) array, ByteDance interview sharing

MySQL约束与多表查询实例分析

剑指 Offer 62. 圆圈中最后剩下的数字

Cross domain? Homology? Understand what is cross domain at once

【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享

leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)

How to solve MySQL master-slave delay problem

【毕业季】研究生学长分享怎样让本科更有意义

How to execute an SQL in MySQL

Ar Augmented Reality applicable scenarios
随机推荐
MySQL constraints and multi table query example analysis
leetcode2310. The one digit number is the sum of integers of K (medium, weekly)
剑指 Offer 47. 礼物的最大价值
The middle element and the rightmost element of the shutter
JPM 2021 most popular paper released (with download)
With the innovation and upgrading of development tools, Kunpeng promotes the "bamboo forest" growth of the computing industry
Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
1069. Division of convex polygons (thinking, interval DP)
【深度学习】infomap 人脸聚类 facecluster
np. Where and torch Where usage
Five skills of adding audio codec to embedded system
How to execute an SQL in MySQL
剑指 Offer II 031. 最近最少使用缓存
mysql列转行函数指的是什么
flutter 中間一個元素,最右邊一個元素
Construction and maintenance of business websites [15]
how to come in an investnent bank team
2022 Q2 - résumé des compétences pour améliorer les compétences
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
【OpenCV】-5种图像滤波的综合示例