Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A,贴个代码吧。。

Posted by ZxyElf at 2013-02-03 23:02:46 on Problem 1089
#include <iostream>
#include <algorithm>
using namespace std;

struct interval{
	int a,b;
}I[50000];

int cmp(const void * a,const void * b){
	interval *aa,*bb;
	aa=(interval*)a;
	bb=(interval*)b;
	if (aa->a==bb->a)
		return bb->b-aa->b;
	else if (aa->a<bb->a)
		return -1;
	return 1;
}

int main()
{
	int n;
	int i,j;
	scanf("%d",&n);
	for (i=0;i<n;i++) scanf("%d%d",&I[i].a,&I[i].b);
	qsort(I,n,sizeof(interval),cmp);
	int a,b;
	a=I[0].a,b=I[0].b;
	for (i=1;i<n;i++){
		if (I[i].a>b){
			printf("%d %d\n",a,b);
			a=I[i].a;
			b=I[i].b;
		}
		else b=max(I[i].b,b); 
	}
	printf("%d %d\n",a,b);
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator