当前位置:网站首页>Block 1110 reversal
Block 1110 reversal
2022-06-10 03:17:00 【NEFU AB-IN】
Powered by:NEFU AB-IN
List of articles
1110 Block inversion
The question
Given a single chain table L, We will every K A node is regarded as a block ( If the linked list is insufficient at the end K Nodes , Also as a block ), Please write a program to L The links of all blocks in are reversed . for example : Given L by 1→2→3→4→5→6→7→8,K by 3, Then the output should be 7→8→4→5→6→1→2→3.
Ideas
Traversal after creating a single linked list , Put the head nodes of each group into vector, And reverse order , Finally, output
Code
/* * @Author: NEFU AB-IN * @Date: 2022-06-04 11:45:48 * @FilePath: \ACM\GPLT\1110.cpp * @LastEditTime: 2022-06-04 12:57:32 */ #include <bits/stdc++.h> using namespace std; #define SZ(X) ((int)(X).size()) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DEBUG(X) cout << #X << ": " << X << endl; typedef pair<int, int> PII; const int N = 1e6 + 10; int h, e[N], ne[N]; int n, k; signed main() { IOS; cin >> h >> n >> k; for (int i = 1; i <= n; ++i) { int addr, data, nxt; cin >> addr >> data >> nxt; e[addr] = data; ne[addr] = nxt; } vector<int> lst; int cnt = 0; for (int i = h; ~i; i = ne[i]) { if (cnt == 0) { lst.push_back(i); } cnt += 1; if (cnt == k) cnt = 0; } vector<int> ans; reverse(lst.begin(), lst.end()); for (auto addr : lst) { for (int i = addr, cnt = 0; ~i && cnt < k; i = ne[i], cnt++) { ans.push_back(i); } } for (int i = 0; i < SZ(ans); ++i) { if (i != SZ(ans) - 1) printf("%05d %d %05d\n", ans[i], e[ans[i]], ans[i + 1]); else printf("%05d %d -1\n", ans[i], e[ans[i]]); } return 0; }
边栏推荐
- How to distinguish the attributes of the object itself from those on the prototype
- The hcie Routing & switching test is postponed to December 31, 2022
- 重构--代码坏味道
- In the new year of hybrid, does BYD really want to reverse its rating?
- Robustness problem -- a work of Enlightenment
- P1516 青蛙的约会(扩欧)
- M3u8 label and attribute description in m3u8 file
- Tensorflow.js入门之mobilenet
- Idea start multiple services with the same set of code
- 17正交矩阵和Gram-Schmidt正交化
猜你喜欢

文本输入,js防注入,识别网址

TS 23.122

Is long-term hotel rental a good business?

架构的演变

剑指 Offer 30. 包含 min 函数的栈

Cancel printing useless information in tensorflow, such as tensorflow:autograph could not transform < *> and will run it as is, loading CUDA information, etc

Prise en charge du mode range par le cadre Open Source

The playback capacity of a single video is more than 8000w, so hard core cooking is so superior

样本方差分母为什么是n-1(无偏估计)?

Detailed explanation of zero copy principle
随机推荐
Anaconda modify file save path
Jupyter notebook configuring virtual environments
零拷贝原理详解
uwsgi loading shared libraries:libicui18n.so.58 异常处理
重构--消除重复代码
Tensorflow.js入门之mobilenet
1110 区块反转
Development of direct interface
在不同领域内自相关函数/自协方差函数含义辨析
洛谷 P2678 跳石头
In the new year of hybrid, does BYD really want to reverse its rating?
架构的演变
NLP关键词提取方法总结及实现
TS 38.304
Protobuf basic introduction to installation and use
1px question
EasyExcel 实现动态导入导出
C Looooops(拓展欧几里得)
The annual income is 3.446 billion yuan, and another fellow countryman in Fujian is going to IPO
jupyter notebook配置虚拟环境