简单题。

#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. leetcode404-----简单的树的遍历

    Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two l ...

  2. IntelliJ IDEA 7.0 正式版注册机代码

    好神奇,第一次看见注册机的源代码,自己运行一下.可以是java IDE环境,也可以是配置好jdk的dos环境. 然后输入自己的用户名就可以获得相对应的注册码,输入到软件中即可. 仅供参考,请购买正版. ...

  3. php过滤函数

    addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符 addslashes — 使用反斜线引用字符串 strip_tags — 从字符串中去除 HTML 和 PHP 标记 stri ...

  4. 解决win7和ubuntu双系统ubuntu不能上网的问题

    1.电脑基本配置如下. 我的电脑 戴尔 OptiPlex 9020 Mini Tower操作系统 Windows 7 专业版 64位 SP1 Ubuntu 14.04 2.装系统的过程不再赘述. 可以 ...

  5. kill -0

    http://unix.stackexchange.com/questions/169898/what-does-kill-0-do 检查有没有权限杀他

  6. [转]c++ new带括号和不带括号

    ref:http://m.blog.csdn.net/blog/u012745772/42420443 在new对象的时候有加上(),有不加(),不知道这个到底是什么区别?比如:CBase *base ...

  7. GDT、GDTR、LDT、LDTR的理解

    GDT是全局描述附表,主要存放操作系统和各任务公用的描述符,如公用的数据和代码段描述符.各任务的TSS描述符和LDT描述符.(TSS是任务状态段,存放各个任务私有运行状态信息描述符)LDT是局部描述符 ...

  8. linux ubuntu下如何安装并且切换java版本(Unsupported major.minor version 52.0)

    最近在做一个dcos(数据中心操作系统)的东西,需要用marathon来做进程管理.遗憾的是0.6版本的marathon在API方面很是缺少,换成了0.15版本之后,运行时提示“Unsupported ...

  9. 超棒的自定义超酷滚动条jQuery插件 - Perfect Scrollbar

    可能大家厌倦了千篇一律的页面滚动条,如果你希望能够设计出与众不同的页面UI设计的话,Perfect ScrollBar可能就是你寻找的解决方案. 这个滚动条来自于一个个人项目,一个简单但是非常棒的滚动 ...

  10. layer弹出层

    最近因为项目要求做了一个layer弹出层demo,先看效果图 好了,现在开始上代码 index.jsp <%@ page language="java" import=&qu ...