简单题。

#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. JAVA序列化与反序列化三种格式存取(默认格式、XML格式、JSON格式)

    什么是序列化 java中的序列化(serialization)机制能够将一个实例对象的状态信息写入到一个字节流中,使其可以通过socket进行传输.或者持久化存储到数据库或文件系统中:然后在需要的时候 ...

  2. JTAG上有多个设备时,该如何接呢?

    首先要了解JTAG管脚相关定义,具有JTAG口的芯片都有如下JTAG引脚定义(是相对芯片): TCK——测试时钟输入: TDI——测试数据输入: TDO——测试数据输出: TMS——测试模式选择,TM ...

  3. eclipse使用外部maven时multiModuleProjectDirectory错误解决

    错误提醒: -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment vari ...

  4. Infix expressions 中缀表达式

    中缀表达式的计算 利用两个栈来实现,操作数栈,操作符栈 只支持个位数运算 最后必须输入一个'#' #include<iostream> using namespace std; templ ...

  5. Why isn't sizeof for a struct equal to the sum of sizeof of each member?

    check here. Basically the compiler will insert unused memory into a structure so that data members a ...

  6. OpenGL------在Windows系统中显示文字

    增加了两个文件,showline.c, showtext.c.分别为第二个和第三个示例程序的main函数相关部分.在ctbuf.h和textarea.h最开头部分增加了一句#include <s ...

  7. Object对象

    1.Object类:所有类的根类.是不断抽取而来的,具备所有对象都具有的共性内容.其中的方法,任何对象都可以调用.继承而来的. equals()方法: Object类的equals源码:比较两个对象是 ...

  8. Windows下将ImageMagick移植到Android平台

    Windows下将ImageMagick移植到Android平台 原文链接  http://www.pedant.cn/2014/06/18/imagemagick-ported-android/ I ...

  9. PullToRefreshListView上拉加载、下拉刷新

    说明:此项目使用studio完成的.需要导入library作为依赖,使用了xuitls获得网络请求.使用Pull解析了XML eclipse中的项目: //注意:此刷新功能是使用的第三方的PullTo ...

  10. AI 人工智能 探索 (二)

    完整被动技能代码 using UnityEngine; using System.Collections; public class AI : MonoBehaviour { private Hash ...