40分求调orz
查看原帖
40分求调orz
1576696
KatsuraJiu楼主2024/12/4 01:28

过了1;12;14-19这8个测试点,其他点报错WA

#include <stdio.h>
#include <stdlib.h>

struct node{
	int country;
	int t;
	struct node* next;
};
//使用链表构造队列,记录每一个乘客的国籍,和到达时间

struct res{
	int country;
	int num;
	int t;
};
//记录各个国籍的总人数

struct k{
	int data;
	struct k* next;
};
//记录答案,最后输出

struct res b[100010];

struct k* H=0;
struct k* R=0;

struct node* head=0;
struct node* rear=0;

void newnode (int x,int time);
//将数据插入队列
void pri ();
int dele (int ti);
//从队列删除数据
void insert (int x);
int su (int a[],int t,int x,int s);
//计算答案的函数

int main()
{
	int n=0;
	int i=0;
	int m=0;
	int cot=0;
	int sum=0;
	int a[300005];
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		
		while(cot!=1){
			scanf("%d",&a[m]);
			if(m>1&&m-1==a[1]){
				cot=1;
			}
			m++;
		}
		
		sum=su(a,a[0],a[1],sum);
		insert(sum);
		cot=0;
		m=0;
	}
	
	pri();
	
	return 0;
}

void newnode (int x,int time)
{
	struct node* t=(struct node*)malloc(sizeof(struct node));
	
	if(head==0){
		t->country=x;
		t->t=time;
		t->next=head;
		head=t;
		rear=t;
		return;
	}else{
		t->country=x;
		t->t=time;
		t->next=0;
		rear->next=t;
		rear=t;
		return;
	}		
}

void insert (int x)
{
	struct k *tem=(struct k*)malloc(sizeof(struct k));
	
	tem->data=x;
	tem->next=0;
	
	if(H==0){
		tem->next=H;
		H=tem;
		R=tem;
		return;
	}else{
		R->next=tem;
		R=tem;
		return;
	}		
}

void pri ()
{
	struct k* t=0;
	t=H;
	while(t!=0){
		printf("%d\n",t->data);
		t=t->next;
	}
}

int dele (int ti)
{
	struct node* te=0;
	int h=0;
	int m=0;
	
	while(head!=0&&head->t==ti){
		te=head;
		head=te->next;
		
		h=te->country;
		b[h].num--;
		if(b[h].num==0){
			m++;
		}
//在从队列删除乘客数据的同时,将这一乘客所属国籍总人数-1,如果总人数归零,就在返回值+1,让答案减去返回值
		
		free(te);
	}
	
	if(head==0){
		head=rear=0;
	}
	
	return m;
}

int su (int a[],int t,int x,int s)
{
	int T=0;
	int mu=0;
	int i=0;
	int m=0;
	
	if(head!=0&&((head->t)<=(t-86400))){
		T=head->t;
		mu=dele(T);
		s=s-mu;
	}
//如果新入港的船与最早达到的船时间相差一天,去除,过时的船的乘客的数据
	
	for(i=2;i<=x+1;i++){
		m=a[i];
		b[m].country=m;
		b[m].num++;
		if(b[m].num==1){
			s++;
		}
//如果某一国籍第一次出现,将答案加一
		newnode(m,t);
//记录船上每一乘客的信息
	}
	
	return s;
}

2024/12/4 01:28
加载中...