当前位置:网站首页>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
边栏推荐
- Sword finger offer 62 The last remaining number in the circle
- Cross domain? Homology? Understand what is cross domain at once
- The middle element and the rightmost element of the shutter
- OpenCASCADE7.6编译
- how to come in an investnent bank team
- 2022 Q2 - résumé des compétences pour améliorer les compétences
- Summary of some experiences in the process of R & D platform splitting
- Construction and maintenance of business websites [15]
- "C language programming", 4th Edition, edited by he Qinming and Yan Hui, after class exercise answers Chapter 3 branch structure Exercise 3
- leetcode2312. 卖木头块(困难,周赛)
猜你喜欢
Selection of field types for creating tables in MySQL database
MySQL中一条SQL是怎么执行的
跨域?同源?一次搞懂什么是跨域
JPM 2021 most popular paper released (with download)
leetcode373. 查找和最小的 K 对数字(中等)
Leetcode face T10 (1-9) array, ByteDance interview sharing
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
【带你学c带你飞】4day第2章 用C语言编写程序(练习 2.5 生成乘方表与阶乘表
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
Which is a good Bluetooth headset of about 300? 2022 high cost performance Bluetooth headset inventory
随机推荐
花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
golang---锁
CSDN insertion directory in 1 second
STM32F103——两路PWM控制电机
JMeter (II) - install the custom thread groups plug-in
附加:信息脱敏;
Sword finger offer 29 Print matrix clockwise
Design and implementation of key value storage engine based on LSM tree
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
The difference between new and malloc
np. Where and torch Where usage
软件开发生命周期 --瀑布模型
Is the knowledge of University useless and outdated?
大厂裁员潮不断,双非本科出身的我却逆风翻盘挺进阿里
MySQL view concept, create view, view, modify view, delete view
How does MySQL solve the problem of not releasing space after deleting a large amount of data
研发中台拆分过程的一些心得总结
2022 Q2 - 提升技能的技巧总结
JMeter (I) - download, installation and plug-in management
How to execute an SQL in MySQL