NYOJ891 找点

时间:2014-03-15 09:27:34   收藏:0   阅读:427

原题链接

思路:将每个区间段按照右端点从小到大排序,count赋值为n,从第一个开始以右端点为基准判断是否在接下来的区段中间,若在则--count。

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

struct Node{
	int x, y;
};

Node arr[101];

int cmp(const void *a, const void *b){
	return (*(Node *)a).y - (*(Node *)b).y;
}

int main(){
	int n, i, j, count;
	while(scanf("%d", &n) == 1){
		for(i = 0; i != n; ++i)
			scanf("%d%d", &arr[i].x, &arr[i].y);
		qsort(arr, n, sizeof(Node), cmp);
		
		for(i = 0, count = n; i != n; ++i){
			for(j = i + 1; j < n; ++j)
				if(arr[i].y <= arr[j].y && arr[i].y >= arr[j].x)
					--count;
				else{
					i = j - 1;
					break;	
				}			
			if(j == n) break;
		}
		printf("%d\n", count);
	}
	return 0;
}


NYOJ891 找点,布布扣,bubuko.com

原文:http://blog.csdn.net/chang_mu/article/details/21259267

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!