当前位置:网站首页>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
边栏推荐
- 734. Energy stone (greed, backpack)
- An analysis of circuit for quick understanding
- Is the knowledge of University useless and outdated?
- leetcode2305. 公平分发饼干(中等,周赛,状压dp)
- oracle创建只读权限的用户简单四步走
- 【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
- leetcode2312. Selling wood blocks (difficult, weekly race)
- The concept, function, characteristics, creation and deletion of MySQL constraints
- Sword finger offer 29 Print matrix clockwise
- leetcode2312. 卖木头块(困难,周赛)
猜你喜欢

Design and implementation of key value storage engine based on LSM tree

【OpenCV】-5种图像滤波的综合示例

跨域?同源?一次搞懂什么是跨域

How to use a product to promote "brand thrill"?

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

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

SQLite 3 of embedded database

Selection of field types for creating tables in MySQL database

Webgpu (I): basic concepts

leetcode2305. Fair distribution of biscuits (medium, weekly, shaped pressure DP)
随机推荐
1069. Division of convex polygons (thinking, interval DP)
* and & symbols in C language
Regular expression learning notes
No programming code technology! Four step easy flower store applet
How does MySQL solve the problem of not releasing space after deleting a large amount of data
Flutter un élément au milieu, l'élément le plus à droite
The middle element and the rightmost element of the shutter
花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案
Opengauss database backup and recovery guide
trading
Duplicate keys detected: ‘0‘. This may cause an update error. found in
leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
【带你学c带你飞】2day 第8章 指针(练习8.1 密码开锁)
正则表达式学习笔记
JMeter (I) - download, installation and plug-in management
【读书笔记】程序员修炼手册—实战式学习最有效(项目驱动)
分卷压缩,解压
How to build and use redis environment
np.where 和 torch.where 用法
Golang lock