閱讀245 返回首頁    go 阿裏雲 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 排序算法係列之冒泡排序