PAT (Advanced Level) 1052. Linked List Sorting (25)
简单题。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<stack>
#include<vector>
using namespace std; const int maxn=+;
int n,h;
struct X
{
int a,b,c;
} node[maxn],p[maxn];
int f[maxn]; bool cmp(const X&a,const X&b)
{
return a.b<b.b;
} int main()
{
memset(f,,sizeof f);
scanf("%d%d",&n,&h); for(int i=; i<=n; i++)
{
scanf("%d%d%d",&node[i].a,&node[i].b,&node[i].c);
f[node[i].a]=i;
} if(h==-)printf("0 -1\n");
else
{
int now=f[h];
int x=;
while()
{
p[x++]=node[now];
if(node[now].c==-) break;
now=f[node[now].c];
} if(x==)
{
if(h==-) printf("0 -1\n");
else printf("0 %05d\n",h);
} else
{
sort(p,p+x,cmp);
h=p[].a;
printf("%d %05d\n",x,h);
for(int i=; i<x; i++)
{
if(i<x-) printf("%05d %d %05d\n",p[i].a,p[i].b,p[i+].a);
else printf("%05d %d -1\n",p[i].a,p[i].b);
}
}
}
return ;
}
PAT (Advanced Level) 1052. Linked List Sorting (25)的更多相关文章
- PAT 解题报告 1052. Linked List Sorting (25)
1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...
- PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)
Excel can sort records according to any column. Now you are supposed to imitate this function. Input ...
- 【PAT甲级】1052 Linked List Sorting (25 分)
题意: 输入一个正整数N(<=100000),和一个链表的头结点地址.接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址.地址由五位包含前导零的正整数组 ...
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
- Pat 1052 Linked List Sorting (25)
1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- PAT Advanced 1052 Linked List Sorting (25) [链表]
题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...
- PAT甲题题解-1052. Linked List Sorting (25)-排序
三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...
- 1052. Linked List Sorting (25)
题目如下: A linked list consists of a series of structures, which are not necessarily adjacent in memory ...
随机推荐
- java泛型小问题
几年前当Java5还未正式发布的时候,看到过一些人写的介绍Tiger中的新特性,当时对我第一感觉冲击最大的就是泛型(generics)和注释(annotation),因为它们直接影响了我们编码的语法习 ...
- hdu_1392_Surround the Trees(凸包)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 题意:求凸包,不知道的百度 题解:模版题 #include<cstdio> #inc ...
- IoC容器Autofac正篇之解析获取(六)
解析获取的方式有如下几种: Resolve class Program { static void Main(string[] args) { var builder = new ContainerB ...
- 模拟摇奖:从1-36中随机抽出8个不重复的数字(math)
public class Yaojiang { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] a=new int[8 ...
- 二分查找(Binary Search)的基本实现
关于二分查找法二分查找法主要是解决在"一堆数中找出指定的数"这类问题. 而想要应用二分查找法,这"一堆数"必须有一下特征: 1,存储在数组中2,有序排列 所以如 ...
- Linux 系统监控
*lsof 列出打开的文件 常用 lsof -i:8080*htop进程监控iotop(bugs)iptraf实时局域网IP监控psacct 监视用户活动monit Linux进程和服务监控工具* ...
- asp.net 基础
前台HTML,javascript,后台C# 代码能不在后台写,就不在后台写 WebSite和WebApplication的区别 1)当改变后台代码时,WebApplication需重启浏览器或者重新 ...
- Python 入门基础学习
Python入门学习 我们使用python3.0版本 首选来入门 带你进入Hello World >>> print ("Hello World")Hell ...
- 虚拟机centos分区
在计算机上安装 Linux 系统,对硬盘进行分区是一个非常重要的步骤,下面介绍几个分区方案. 方案 1 / :建议大小在 5GB 以上. swap :即交换分区,建议大小是物理内存的 1~2 倍. 方 ...
- HDU4815/计数DP
题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=4815] 简单说一下题意: 有n道题,每到题答对得分为a[ i ],假如A不输给B的最小概率是P,那么A ...