当前位置:网站首页>Pat grade a real problem 1165
Pat grade a real problem 1165
2022-06-29 01:18:00 【Ray. C.L】

Ideas : Same as word flipping , Turn over as a whole first , Then flip the length to K The range of
Code :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
int h, n, m;
int ne[N], w[N];
int q[N];
int main()
{
scanf("%d%d%d",&h, &n, &m);
while (n -- ){
int addr,next,val;
scanf("%d%d%d",&addr, &val, &next);
w[addr] = val;
ne[addr] = next;
}
int cnt = 0;
for(int i = h; i != -1; i = ne[i])
q[cnt++] = i;
reverse(q, q + cnt);
for(int i = cnt - 1; i >= 0; i -= m)
reverse(q + max(0, i - m + 1), q + i +1);
for(int i = 0; i < cnt; i++){
int addr = q[i], next = q[i + 1];
printf("%05d %d ", addr, w[addr]);
if(cnt - 1 == i) puts("-1");
else printf("%05d\n", next);
}
return 0;
}
边栏推荐
- [MCU club] design of classroom number detection based on MCU [physical design]
- Vulnerability mining | routine in password retrieval
- Misunderstanding of innovation by enterprise and it leaders
- [UVM] my main_ Why can't the case exit when the phase runs out? Too unreasonable!
- TypeScript(6)函数
- 统计字符串中不同回文子序列的个数
- Basic use of flask Sqlalchemy
- 手把手教你搞懂测试环境项目部署
- Successfully solved (machine learning data segmentation problem): modulenotfounderror: no module named 'sklearn cross_ validation‘
- [image processing] image curve adjustment system based on MATLAB
猜你喜欢

《Reinforcement learning based parameters adaption method for particleswarm optimization》代码复现

BMFONT制作位图字体并在CocosCreator中使用

TypeScript(4)接口

GUI Graphical user interface programming example - color selection box

After easycvr creates a new user, the video access page cannot be clicked. Fix the problem

Werewolf kill casual game wechat applet template source code / wechat game source code

Easycvr service private What should I do if the PEM file is emptied and cannot be started normally?

Docker中安装Oracle数据库

Rasa dialogue robot helpdesk (V)

What kind of life is a tester with a monthly salary of over 10000?
随机推荐
[MCU club] design of GSM version of range hood based on MCU [simulation design]
4276. 擅长C
企业和IT领导者对创新的误解
Easycvr service private What should I do if the PEM file is emptied and cannot be started normally?
[MCU club] design of GSM version of range hood based on MCU [physical design]
IPFS简述
Drawing ECG curve with WPF
启牛学堂帮忙开证券账户是安全靠谱的吗?个人如何开
Installing Oracle database in docker
What is the reason why easycvr can't watch the device video when it is connected to the home protocol?
Different subsequence problems I
Sword finger offer 14- I. cut rope
接雨水系列问题
Finally understand the difference between DOM XSS and reflection XSS
SRAM和DRAM之间的异同
[MCU club] design of blind water cup based on MCU [simulation design]
linux7(centos7)设置oracle11开机自启动
致我们曾经遇到过的接口问题
802.1x协议简述
Breadth first search to catch cattle