简单题。

#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)的更多相关文章

  1. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  2. 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 ...

  3. 【PAT甲级】1052 Linked List Sorting (25 分)

    题意: 输入一个正整数N(<=100000),和一个链表的头结点地址.接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址.地址由五位包含前导零的正整数组 ...

  4. 【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 ...

  5. Pat 1052 Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  6. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  7. PAT Advanced 1052 Linked List Sorting (25) [链表]

    题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...

  8. PAT甲题题解-1052. Linked List Sorting (25)-排序

    三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...

  9. 1052. Linked List Sorting (25)

    题目如下: A linked list consists of a series of structures, which are not necessarily adjacent in memory ...

随机推荐

  1. zencart 后台目录产品黄色icon_yellow_on.gif 解决方案

    解决方法,导入时候发现 更新成功! - 型号: as NO.1209 就是重复model 文件位置:manager\includes\modules\category_product_listing. ...

  2. Chapter 1 First Sight——31

    I took notes carefully anyway, always looking down. 不论怎么样我都仔细的记着笔记,一直低着头. I couldn't stop myself fro ...

  3. mvn 下载源码和javadoc

    1. 下载源码,两种: . mvn dependency:sources . mvn eclipse:eclipse -DdownloadSources=true 2. 下载javadoc,两种: . ...

  4. JavaScript高级程序设计:第十四章

    第十四章 一.表单的基础知识 在HTML中,表单是由<form>元素来表示的,而在javascript中,表单对应的则是HTMLFormElement类型.HTMLFormElement继 ...

  5. SNMP学习之结构体snmp_secmod_def

    此结构体中定义了各个回调函数,在函数init_ksm(E:\code\net-snmp-5.4.2.1\snmplib)中进行了初始化. void init_ksm(void) { struct sn ...

  6. Java Web项目发布及使用自定义域名

    详细讲解的网址: http://wenku.baidu.com/link?url=-ACZxKUcfrbhrMRUP3Ov-Q_c-Q9JPrA9D1fzHjHuJsWwZfRsVDVQ2qBtoY7 ...

  7. div style设置隐藏多余字, title设置鼠标放上显示出来全部

    <div style='overflow: hidden; white-space: nowrap; text-overflow: ellipsis;' title='"+data[j ...

  8. springboot 打包

    springboot 打包 先clean 然后 maven package 通过命令java -jar target/GoshenWepPro-0.1.0.jar运行程序

  9. cmd命令行查看当前系统版本和版本是32位还是64位

  10. 获取输入设备的vid和pid

    一.获取/dev/input/event16设备的vid和pid testhid.c #include <linux/types.h> #include <linux/input.h ...