`
com_xpp
  • 浏览: 353961 次
社区版块
存档分类
最新评论

会场安排问题(贪心)

 
阅读更多
/*日期:2011-10-17
作者:xiaosi
题目:会场安排问题(贪心)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=14
*/
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
struct Activity
{
int begin;
int end;
}A[10000];
int cmp(const void *a,const void *b)
{
struct Activity *c = (Activity *)a;
struct Activity *d = (Activity *)b;
return c->end - d->end;
}
int Selector(Activity A[],int n)
{
int i,j=0,count=1;
for(i=1;i<n;i++)
{
if(A[i].begin > A[j].end)
{
count++;
j=i;
}
}
return count;
}
int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
while(N--)
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&A[i].begin,&A[i].end);
}
qsort(A,n,sizeof(A[0]),cmp);
printf("%d\n",Selector(A,n));
}
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics