Topic links: Click here
Title effect: initially given a list, sorted according to the requirements needed:
- When the junction is in the negative, it is necessary at the top
- When the junction is in the non-negative and less than the threshold k, the middle row
- When the value of the node is greater than a threshold value k, the last row
While the overall ranking as much as possible not to change the original order
Topic Analysis: With the experience of the last do list title after the simulation, the subject was more smoothly, because the rules explicitly ordering requirements are divided into three levels, then we look at the way the storage level of the node that is stored in the linked list It can last scratch node running side chain, to the serial number on each node programmed, so that, when ordering, according to the first priority level are ordered, if the same level can be sorted according to the number
There is a very sick man pits, really served the sick person's ability pat, wave cow brush
4 test points, the data will be given a lot of single node, the node is not any relationship with the list of topics as described, then we need to sort and exclude output, the very good treatment, a ghost can think of ah, we only need to retain the list cnt while each node numbering, can be used instead of the n cnt
Code:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const int N=1e5+100;
struct Node
{
int date,next;
int flag;
int id;
}node[N];
int ans[N];
bool cmp(int a,int b)
{
Node aa=node[a];
Node bb=node[b];
if(aa.flag!=bb.flag)
return aa.flag>bb.flag;
return aa.id<bb.id;
}
int main()
{
// freopen("input.txt","r",stdin);
int head,n,k;
scanf("%d%d%d",&head,&n,&k);
for(int i=1;i<=n;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
node[a].date=b;
node[a].next=c;
if(node[a].date<0)
node[a].flag=2;
else if(node[a].date<=k)
node[a].flag=1;
else
node[a].flag=0;
}
int cnt=0;
for(int i=head;i!=-1;i=node[i].next)
{
ans[++cnt]=i;
node[i].id=cnt;
}
sort(ans+1,ans+1+cnt,cmp);
for(int i=1;i<=cnt;i++)
{
if(i!=cnt)
printf("%05d %d %05d\n",ans[i],node[ans[i]].date,ans[i+1]);
else
printf("%05d %d %d\n",ans[i],node[ans[i]].date,-1);
}
return 0;
}