当前位置:网站首页>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
边栏推荐
- Construction and maintenance of business websites [13]
- 1069. Division of convex polygons (thinking, interval DP)
- Architecture evolution from MVC to DDD
- Infix expression to suffix expression (computer) code
- Design and implementation of key value storage engine based on LSM tree
- Construction and maintenance of business websites [14]
- Quality means doing it right when no one is looking
- 2022 Q2 - 提昇技能的技巧總結
- 1222. Password dropping (interval DP, bracket matching)
- An analysis of circuit for quick understanding
猜你喜欢

MySQL主从延迟问题怎么解决

The concept, function, characteristics, creation and deletion of MySQL constraints

Ar Augmented Reality applicable scenarios

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

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

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

花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案

Number of palindromes in C language (leetcode)

A quick understanding of analog electricity

开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
随机推荐
* and & symbols in C language
Software development life cycle -- waterfall model
Construction and maintenance of business websites [14]
STM32F103 - two circuit PWM control motor
Selection of field types for creating tables in MySQL database
[opencv] - comprehensive examples of five image filters
Iterative unified writing method of binary tree
How to use redis ordered collection
Leetcode face T10 (1-9) array, ByteDance interview sharing
Deep learning: a solution to over fitting in deep neural networks
Medical management system (C language course for freshmen)
开发工具创新升级,鲲鹏推进计算产业“竹林”式生长
Sword finger offer 62 The last remaining number in the circle
【带你学c带你飞】4day第2章 用C语言编写程序(练习 2.5 生成乘方表与阶乘表
分卷压缩,解压
Types of exhibition items available in the multimedia interactive exhibition hall
【liuyubobobo-玩转Leetcode算法面试】【00】课程概述
how to add one row in the dataframe?
Additional: information desensitization;
pytest 测试框架