简单题。

#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. Chapter 1 First Sight——26

    "Which ones are the Cullens?" I asked. "They don't look related…" 哪一个是卡伦,我问道,他们都 ...

  2. 记一次Jquery获取值的典型错误

    直接上代码: 代码很简单,通过Post的形式提交参数,但是发现提交的data总是空,昨晚有点纳闷,今天一看才发现... 获取值得时候的顺序有问题,获取值应该是在onclick事件中. 综上:写Jque ...

  3. 第三十五节,json数据类型转换字符串模块

    在使用json模块时需要先 import json 引入模块 json.dumps()模块函数 功能:将Python数据类型转换成字符串[有参] 使用方法:json.dumps(要转换的数据类型变量) ...

  4. Infix to postfix conversion 中缀表达式转换为后缀表达式

    Conversion Algorithm 1.操作符栈压入"#": 2.依次读入表达式的每个单词: 3.如果是操作数则压入操作数栈: 4.如果是操作符,则将操作符栈顶元素与要读入的 ...

  5. sql server 2000/2005递归

    /* 递归查询 塗聚文---SQL Server 2005环境下的实现: */--生成测试数据 create table Dept(ID int,ParentID int,msg varchar(20 ...

  6. Ansible3:ansible.cfg配置说明【转】

    Ansible默认安装好后有一个配置文件/etc/ansible/ansible.cfg,该配置文件中定义了ansible的主机的默认配置部分,如默认是否需要输入密码.是否开启sudo认证.actio ...

  7. jquery滚动条加载数据

    //滚动条  $(window).scroll(function () {   var scrollTop = $(this).scrollTop();   var scrollHeight = $( ...

  8. 状压dp Codeforces Beta Round #8 C

    http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...

  9. postfix日志分析pflogsumm

    1.pflogsumm功能:统计接收.投递.转发.延时.反弹.拒绝.保留.丢弃的邮件统计发件人和收件人 统计发送和接受方主机/域名 统计SMTPD连接数...... 2.安装# yum install ...

  10. ccw-ide

    有bug,会把working set弄乱,整理后能重启一次正常,再次重启又乱了.