PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
简单题。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; const int maxn=+;
int root,n;
struct Node
{
int id,val,nx;
}tmp[maxn],s[maxn]; int in[maxn];
int flag[maxn];
int idx[maxn];
int tot=;
vector<int>g[maxn]; int main()
{
memset(in,,sizeof in);
memset(flag,,sizeof flag);
scanf("%d%d",&root,&n);
for(int i=;i<=n;i++){
scanf("%d%d%d",&tmp[i].id,&tmp[i].val,&tmp[i].nx);
in[tmp[i].id]=i;
} int p=root,sz=;
while()
{
if(p==-) break;
s[sz++]=tmp[in[p]];
p=tmp[in[p]].nx;
} for(int i=;i<sz;i++)
{
if(flag[abs(s[i].val)]==) g[].push_back(i);
else g[].push_back(i);
flag[abs(s[i].val)]++;
} for(int i=;i<=;i++)
{
for(int j=;j<g[i].size();j++)
{
if(j==g[i].size()-)
printf("%05d %d %d\n",s[g[i][j]].id,s[g[i][j]].val,-);
else
printf("%05d %d %05d\n",s[g[i][j]].id,s[g[i][j]].val,s[g[i][j+]].id);
}
}
return ;
}
PAT (Advanced Level) 1097. Deduplication on a Linked List (25)的更多相关文章
- PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作
给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
- 【PAT甲级】1097 Deduplication on a Linked List (25 分)
题意: 输入一个地址和一个正整数N(<=100000),接着输入N行每行包括一个五位数的地址和一个结点的值以及下一个结点的地址.输出除去具有相同绝对值的结点的链表以及被除去的链表(由被除去的结点 ...
- PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642
PAT (Advanced Level) Practice 1002 A+B for Polynomials (25 分) 凌宸1642 题目描述: This time, you are suppos ...
- PAT (Advanced Level) Practise - 1097. Deduplication on a Linked List (25)
http://www.patest.cn/contests/pat-a-practise/1097 Given a singly linked list L with integer keys, yo ...
- PAT Advanced 1097 Deduplication on a Linked List (25) [链表]
题目 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplica ...
- 1097. Deduplication on a Linked List (25)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...
- PAT (Advanced Level) 1106. Lowest Price in Supply Chain (25)
简单dfs #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1090. Highest Price in Supply Chain (25)
简单dfs. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1079. Total Sales of Supply Chain (25)
树的遍历. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
随机推荐
- iOS 时间戳的问题
- (NSString *)timeWithTimeIntervalString:(NSString *)timeString { // 格式化时间 NSDateFormatter* formatte ...
- iOS学习笔记(01) - 泛型
决定新开一坑,在不断学习的同时分享自己的学习历程给大家,既是对自己学习的记录,又希望能对大家提供些微的帮助. 这一篇文章主要来介绍泛型的意义.使用与声明方法等. 1.泛型:限制类型 1.1.泛型使用场 ...
- Heap Operations(模拟题)
Heap Operations time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- UVA 12083 POJ 2771 Guardian of Decency
/* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...
- NEU OJ 1651 Great number
循环节是2000000016 字符串读入,用一下高精度对2000000016取个模,用一下快速幂就可以算出答案了. #include <cstdio> #include <iostr ...
- python常用正则表达式
匹配特定数字:^[1-9]\d*//匹配正整数−[1−9]\d∗ //匹配负整数^-?[1-9]\d*//匹配整数[1−9]\d∗|0 //匹配非负整数(正整数 + 0)^-[1-9]\d*|0// ...
- hdu_2224_The shortest path(dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2224 题意:双调欧几里德旅行商经典问题,找一条最短回路使得该路经过所有的点 题解:dp[i][j]=d ...
- Eclipse中配置weka,以及添加算法
Eclipse中配置weka 1 找到weka的安装位置,寻找weka的压缩文件weka-src.jar,将压缩文件解压,解压出的文件夹weka-src. 2 打开Eclipse,新建Java pro ...
- how computer boot up?
The power button activates the power supply in the PC, sending power to the motherboard and other co ...
- kubernetes 条件需求
1. 你必须拥有一台安装有Docker的机器. 2. 你的内核必须支持 memory and swap accounting .确认你的linux内核开启了如下配置: CONFIG_RESOURCE_ ...