PAT (Advanced Level) Practice 1165 Block Reversing
题目
没有用链表,感觉用指针写太麻烦了,想起当初刚学数据结构被链表支配的恐惧。坑点是可能的有不在链表的数据,链表的长度不一定为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相关推荐
- PAT (Advanced Level) Practice 题解代码 - II (1051-1100)
PAT PAT (Advanced Level) Practice - II(1051-1100) -------------------------------------------------- ...
- 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 ...
- 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 ...
- PAT (Advanced Level) Practice 题目集合(1001 ~ 1050)(正在更新)
1001 A+B Format (20 分) 题目大意:计算a+b,结果按照西方的那种写数字的方式输出,从三个数一个逗号那种. #include<bits/stdc++.h> using ...
- 【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 ...
- 【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 ...
- 【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 ...
- 【PAT (Advanced Level) Practice】1086 Tree Traversals Again (25 分)
众所周知只有前序遍历和后序遍历是不可能推出中序遍历的,所以我就不废话了 由树的前序遍历和中序遍历可以推后序遍历 由树的中序遍历和后序遍历可以推前序遍历 #include <cstdio> ...
- 【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 ...
最新文章
- 合肥工业大学—SQL Server数据库实验一:数据库的创建和删除
- Linux下搭建jenkins+svn+http+maven自动化部署
- find与grep命令简介及正则表达式(转)
- 检查字符串是否包含数字的Python程序
- VSCode内npm run build编译打包时候报错:code ELIFECYCLE - (已解决)
- [USACO13MAR]Farm Painting【枚举】
- 图神经网络(二)--GNNs
- uvalive 3713 Astronauts
- python爬虫入门之————————————————案例演练
- java php python校园通知事项打卡 微信小程序系统
- Systemtap学习笔记
- c#通过输入年月日输出该月的天数
- MATLAB 矩阵的NAN值怎么删+绘图颜色设定
- 数据结构-3 堆积木
- Let正版短信测压开源源码
- MTK6592的modem-1.ubuntu14.04下的编译烧写及调试
- html5初学者小游戏源代码,html5游戏代码练习,跑动的小人儿!
- Windows 10升级如何立即进行,不用等微软分批推送?
- 高中优质计算机课ppt课件ppt课件ppt课件ppt课件ppt课件,高中数学课一等奖课件.ppt...
- c语言课设仓库管理系统,c语言课设仓库管理系统.doc