排个序,模拟下就好了,水题一个
/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define INF 1E9
using namespace std;
struct node
{
int x,y;
};
node o[50001];
bool cmp(node a,node b)
{
if(a.y!=b.y)
return a.y>b.y;
return a.x>b.x;
}
int main()
{
int n,i;
while(~scanf("%d",&n)&&n)
{
for(i=0;i<n;i++)
scanf("%d%d",&o[i].x,&o[i].y);
sort(o,o+n,cmp);
int ans=1;
int x=o[0].x;
for(i=0;i<n;i++)
{
if(o[i].x>x)
{
x=o[i].x;
ans++;
}
}
printf("%d\n",ans);
}
}

本文介绍了一个简单的排序问题解决方法,通过C/C++实现了一个具体的排序算法应用案例。该案例涉及结构体定义、自定义比较函数及标准库sort函数的使用,并展示了如何通过排序算法解决实际问题。
149

被折叠的 条评论
为什么被折叠?



