用链表实现,这或许不是最好的算法,但过网教的案例是没问题的
#include "stdio.h"
#include "stdlib.h"
typedef struct poster{
int pos_left;
int pos_right;
int number;
struct poster*next;
}poster;
int main()
{
int group,num_data,count,num_l,num_r,ans,flag_pre,flag_now;
poster *head,*make_data,*pre;
poster *point,*node_free,*new;
scanf("%d",&group);
while (group--) {
scanf("%d",&num_data);
head=(poster*)malloc(sizeof(poster));
head->number=0;
head->next=NULL;
pre=head;
for (count=1; count<=num_data; count++) {
scanf("%d %d",&num_l,&num_r);
make_data=(poster*)malloc(sizeof(poster));
pre->next=make_data;
make_data->pos_left=num_l;
make_data->pos_right=num_r;
make_data->number=count