#include
<
iostream
>
using
namespace
std;
struct
arr{
int
x,y;
}a[
101
];
int
N;
int
f[
101
]
=
{
0
};
int
cmp(
const
void
*
no1,
const
void
*
no2){
arr
*
nox
=
(arr
*
)no1,
*
noy
=
(arr
*
)no2;
return
nox
->
y
-
noy
->
y;
}
int
main()
{
cin
>>
N;
for
(
int
i
=
0
;i
<
N;
++
i){
cin
>>
a[i].x
>>
a[i].y;
if
(a[i].x
>
a[i].y){
int
tmp
=
a[i].x;
a[i].x
=
a[i].y;
a[i].y
=
tmp;
}
}
qsort(a,N,
sizeof
(arr),cmp);
int
ans
=
0
;
for
(
int
i
=
0
;i
<
N;
++
i)
if
(
!
f[i]){
for
(
int
j
=
i
+
1
;j
<
N;
++
j)
if
(
!
f[j]
&&
a[i].y
>
a[j].x)
f[j]
=
1
;
ans
++
;
}
cout
<<
ans
<<
endl;
for
(
int
i
=
0
;i
<
N;
++
i)
if
(
!
f[i])
cout
<<
a[i].x
<<
"
"
<<
a[i].y
<<
endl;
return
0
;
}
1203:
#include<iostream>
using namespace std;
struct arr{
int x,y;
}a[100010];
int N;
bool f[100010]={0};
int cmp(const void* no1,const void* no2){
arr *nox=(arr*)no1,*noy=(arr*)no2;
return nox->y-noy->y;
}
int main()
{
scanf("%d",&N);
for(int i=0;i<N;++i)
scanf("%d%d",&a[i].x,&a[i].y);
qsort(a,N,sizeof(arr),cmp);
int k=0;
for(int i=0;i<N;++i){
if(!f[i])
for(int j=i+1;j<N;++j)
if(a[i].y>=a[j].x)
f[j]=1;
if(!f[i]) k++;
}
printf("%d\n",k);
return 0;
}
posted on 2009-06-01 13:17
xfstart07 阅读(154)
评论(0) 编辑 收藏 引用 所属分类:
代码库