题目
没有用链表,感觉用指针写太麻烦了,想起当初刚学数据结构被链表支配的恐惧。坑点是可能的有不在链表的数据,链表的长度不一定为n.

#include <bits/stdc++.h>
using namespace std;
const int N=1e6;
int judge1[N], judge2[N], v[N];int main()
{int st, n, k, a, b, c;scanf("%d%d%d", &st, &n, &k);for(int i=0; i<n; i++) {scanf("%d%d%d", &a, &b, &c);judge1[a]=b;judge2[a]=c;}int i=0;n=0;while(st!=-1) {v[i++]=st;st=judge2[st];n+=1;}int j=n/k;if(n%k)i=n-n%k;else {i=n-k;j-=1;}while(true){printf("%05d %d ", v[i], judge1[v[i]]);i+=1;if(i==n || i%k==0){j-=1;if(j<0)break;i=j*k;}printf("%05d\n", v[i]);}printf("-1\n");return 0;
}
/*
00100 9 3
71120 7 88666
00000 4 99999
00100 1 12309
68237 6 71120
33218 3 00000
99999 5 68237
88666 8 -1
12309 2 33218
10000 10 19999
*/

PAT (Advanced Level) Practice 1165 Block Reversing相关推荐

  1. PAT (Advanced Level) Practice 题解代码 - II (1051-1100)

    PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...

  2. PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642

    PAT (Advanced Level) Practice 1043 Is It a Binary Search Tree (25 分) 凌宸1642 题目描述: A Binary Search Tr ...

  3. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  4. PAT (Advanced Level) Practice 题目集合(1001 ~ 1050)(正在更新)

    1001 A+B Format (20 分) 题目大意:计算a+b,结果按照西方的那种写数字的方式输出,从三个数一个逗号那种. #include<bits/stdc++.h> using ...

  5. 【PAT (Advanced Level) Practice】1093 Count PAT‘s (25 分)

    1093 Count PAT's (25 分) The string APPAPT contains two PAT's as substrings. The first one is formed ...

  6. 【PAT (Advanced Level) Practice】1124 Raffle for Weibo Followers (20 分)

    1124 Raffle for Weibo Followers (20 分) John got a full mark on PAT. He was so happy that he decided ...

  7. 【PAT (Advanced Level) Practice】1149 Dangerous Goods Packaging (25 分)

    1149 Dangerous Goods Packaging (25 分) When shipping goods with containers, we have to be careful not ...

  8. 【PAT (Advanced Level) Practice】1086 Tree Traversals Again (25 分)

    众所周知只有前序遍历和后序遍历是不可能推出中序遍历的,所以我就不废话了 由树的前序遍历和中序遍历可以推后序遍历 由树的中序遍历和后序遍历可以推前序遍历 #include <cstdio> ...

  9. 【PAT (Advanced Level) Practice】1051 Pop Sequence (25 分)

    1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the order ...

最新文章

  1. 合肥工业大学—SQL Server数据库实验一:数据库的创建和删除
  2. Linux下搭建jenkins+svn+http+maven自动化部署
  3. find与grep命令简介及正则表达式(转)
  4. 检查字符串是否包含数字的Python程序
  5. VSCode内npm run build编译打包时候报错:code ELIFECYCLE - (已解决)
  6. [USACO13MAR]Farm Painting【枚举】
  7. 图神经网络(二)--GNNs
  8. uvalive 3713 Astronauts
  9. python爬虫入门之————————————————案例演练
  10. java php python校园通知事项打卡 微信小程序系统
  11. Systemtap学习笔记
  12. c#通过输入年月日输出该月的天数
  13. MATLAB 矩阵的NAN值怎么删+绘图颜色设定
  14. 数据结构-3 堆积木
  15. Let正版短信测压开源源码
  16. MTK6592的modem-1.ubuntu14.04下的编译烧写及调试
  17. html5初学者小游戏源代码,html5游戏代码练习,跑动的小人儿!
  18. Windows 10升级如何立即进行,不用等微软分批推送?
  19. 高中优质计算机课ppt课件ppt课件ppt课件ppt课件ppt课件,高中数学课一等奖课件.ppt...
  20. c语言课设仓库管理系统,c语言课设仓库管理系统.doc

热门文章

  1. 聚合支付怎么开发的,模式有哪些
  2. open edx 实现第三方登录-shibboleth单点登录
  3. php数组去重的函数,php数组去重函数的简单示例
  4. 甲乙丙丁四个人去商店每人买了一台计算机,寒假数学作业一
  5. ros借助讯飞sdk实现问答机器人解决讯飞语音sdk11212erro
  6. 复制移动文件时对于目标文件系统过大怎么办
  7. 计算机动漫于游戏制作江阴南华,动画实习教案.docx
  8. 知识付费陷“知识焦虑”,谁在为知识买单?
  9. react脚手架honeycomb部署
  10. 模拟退火——算法思想与实例