阅读245 返回首页    go 技术社区[云栖]


poj 1828 Monkeys' Pride 模拟

   排个序,模拟下就好了,水题一个


/*
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);
    }
}


最后更新:2017-04-03 18:51:47

  上一篇:go Ubuntu 13.04来袭 Java 8新特性流出
  下一篇:go 排序算法系列之冒泡排序