当前位置:网站首页>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
边栏推荐
- Ar Augmented Reality applicable scenarios
- CSDN insertion directory in 1 second
- leetcode2311. Longest binary subsequence less than or equal to K (medium, weekly)
- Number of palindromes in C language (leetcode)
- 如何用一款产品推动「品牌的惊险一跃」?
- Deep learning: a solution to over fitting in deep neural networks
- [opencv] - comprehensive examples of five image filters
- 2022 Q2 - 提昇技能的技巧總結
- leetcode2305. 公平分发饼干(中等,周赛,状压dp)
- [技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术
猜你喜欢

Spend a week painstakingly sorting out the interview questions and answers of high-frequency software testing / automated testing

【读书笔记】程序员修炼手册—实战式学习最有效(项目驱动)

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

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

leetcode2310. The one digit number is the sum of integers of K (medium, weekly)

【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)

How to use redis ordered collection

MySQL如何解决delete大量数据后空间不释放的问题

MySQL主从延迟问题怎么解决

Opengauss database backup and recovery guide
随机推荐
Leetcode face T10 (1-9) array, ByteDance interview sharing
[question] - why is optical flow not good for static scenes
Deep learning: a solution to over fitting in deep neural networks
How does MySQL solve the problem of not releasing space after deleting a large amount of data
剑指 Offer II 031. 最近最少使用缓存
Infix expression to suffix expression (computer) code
How to debug apps remotely and online?
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Medical management system (C language course for freshmen)
Sword finger offer 29 Print matrix clockwise
软件开发生命周期 --瀑布模型
What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
Word search applet design report based on cloud development +ppt+ project source code + demonstration video
[技术发展-21]:网络与通信技术的应用与发展快速概览-1- 互联网网络技术
MySQL中一条SQL是怎么执行的
mysql列转行函数指的是什么
How to batch add background and transition effects to videos?
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology
Pytest testing framework
Summary of some experiences in the process of R & D platform splitting