| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
这样贪心不知哪里错了,呜呜~大家帮忙看下#include <iostream>
using namespace std;
int n , vis[410];
struct node
{
int b , e;
}ran[210];
int cmp(const void *x , const void *y)
{
struct node * c = (node*)x ;
struct node * d = (node*)y;
if(c->b != d->b)
return c->b - d->b;
return c->e - d->e;
}
int main()
{
int T;
scanf("%d" , &T);
while(T --)
{
scanf("%d" , &n);
int i , j;
for(i = 0 ; i < n ; i ++){
scanf("%d%d" , &ran[i].b , &ran[i].e);
if(ran[i].b > ran[i].e){
int temp = ran[i].b;
ran[i].b = ran[i].e;
ran[i].e = temp;
}
if(ran[i].b%2 == 0)
ran[i].b --;
if(ran[i].e%2 == 1)
ran[i].e ++;
}
memset(vis , 0 , sizeof(vis));
qsort(ran, n , sizeof(ran[0]) , cmp);
int res = 0;
for(i = 0 ; i < n ; i ++){
if(vis[i] == 0){
res ++;
int t = ran[i].e;
vis[i] = 1;
for(j = i + 1; j < n ; j ++){
if(ran[j].b > t){
vis[j] = 1;
t = ran[j].e;
}
}
}
}
printf("%d\n" , 10*res);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator