大佬帮帮我,全超时了QAQ
查看原帖
大佬帮帮我,全超时了QAQ
1184290
Atlanteep楼主2024/1/22 21:31
#include<stdio.h>
#include<stdlib.h>

struct time
{
	int a_start;
	int b_end;
};

int compar(const void* p1, const void* p2)
{
	return ((struct time*)p1)->b_end - ((struct time*)p2)->b_end;
}

int main()
{
	int n;
	scanf("%d", &n);
	struct time race[n];
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &race[i].a_start, &race[i].b_end);
	}
	qsort(race, n, sizeof(struct time), compar);
	
	int count = 0;
	for (int i = 0; i < n; )
	{
		int k = i;
		while (race[i + 1].a_start < race[k].b_end)
		{			
			i++;
		}
		count++;
	}

	printf("%d", count);
	return 0;
}
2024/1/22 21:31
加载中...