PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
Posted Fighting Heart
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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=100000+10; int root,n; struct Node { int id,val,nx; }tmp[maxn],s[maxn]; int in[maxn]; int flag[maxn]; int idx[maxn]; int tot=0; vector<int>g[maxn]; int main() { memset(in,0,sizeof in); memset(flag,0,sizeof flag); scanf("%d%d",&root,&n); for(int i=1;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=0; while(1) { if(p==-1) break; s[sz++]=tmp[in[p]]; p=tmp[in[p]].nx; } for(int i=0;i<sz;i++) { if(flag[abs(s[i].val)]==0) g[0].push_back(i); else g[1].push_back(i); flag[abs(s[i].val)]++; } for(int i=0;i<=1;i++) { for(int j=0;j<g[i].size();j++) { if(j==g[i].size()-1) printf("%05d %d %d\n",s[g[i][j]].id,s[g[i][j]].val,-1); else printf("%05d %d %05d\n",s[g[i][j]].id,s[g[i][j]].val,s[g[i][j+1]].id); } } return 0; }
以上是关于PAT (Advanced Level) 1097. Deduplication on a Linked List (25)的主要内容,如果未能解决你的问题,请参考以下文章
PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
PAT Advanced 1097 Deduplication on a Linked List (25) [链表]