#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
string
.h
>
#define
N 5001
struct
Node
{
int
length;
int
weight;
};
int
n;
Node d[N];
bool
visite[N];
int
cmp(
const
void
*
a,
const
void
*
b )
{
Node
*
ta
=
(Node
*
)a;
Node
*
tb
=
(Node
*
)b;
if
( ta
->
length
==
tb
->
length )
return
ta
->
weight
-
tb
->
weight;
return
ta
->
length
-
tb
->
length;
}
int
main()
{
int
test;
scanf(
"
%d
"
,
&
test);
while
( test
--
)
{
scanf(
"
%d
"
,
&
n );
for
(
int
i
=
0
; i
<
n;
++
i )
scanf(
"
%d%d
"
,
&
d[i].length,
&
d[i].weight );
qsort( d, n,
sizeof
(d[
0
]), cmp );
memset( visite,
false
,
sizeof
(visite) );
int
b
=
d[
0
].weight;
int
num
=
0
;
int
k
=
0
;
while
(
true
)
{
bool
ok
=
false
;
if
( k
==
-
1
)
break
;
b
=
d[k].weight; num
++
;
int
be
=
k; k
=
-
1
;
for
(
int
i
=
be; i
<
n;
++
i )
{
if
( d[i].weight
>=
b
&&
!
visite[i] )
{
visite[i]
=
true
;
b
=
d[i].weight;
}
else
if
(
!
ok
&&
!
visite[i] ) { k
=
i; ok
=
true
; }
}
}
printf(
"
%d\n
"
, num );
}
return
0
;
}
posted on 2008-10-30 20:55
Darren 阅读(335)
评论(0) 编辑 收藏 引用 所属分类:
搜索