zoukankan      html  css  js  c++  java
  • poj1828

    题意:平面上的一些点,问有多少点的右上方没有点(即不存在x,y均比它大的点)。

    分析:本来想 用求逆序数的方法,后来上网发现了更简单的方法。

    按x从小到大,x相等按y从小到大排序后,从右到左,一旦遇到一个比之前见过的y都大的y,就把ans++;

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <algorithm>
    usingnamespace std;

    #define maxn 50005

    struct Point
    {
    int x, y;
    }point[maxn];

    int n;

    void input()
    {
    for (int i =0; i < n; i++)
    scanf(
    "%d%d", &point[i].x, &point[i].y);
    }

    booloperator< (const Point &a, const Point &b)
    {
    if (a.x == b.x)
    return a.y < b.y;
    return a.x < b.x;
    }

    void work()
    {
    int ans =1;
    int maxy = point[n -1].y;
    for (int i = n -2; i >=0; i--)
    {
    if (point[i].y > maxy)
    {
    ans
    ++;
    maxy
    = point[i].y;
    }
    }
    printf(
    "%d\n", ans);
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (scanf("%d", &n), n)
    {
    input();
    sort(point, point
    + n);
    work();
    }
    return0;
    }
  • 相关阅读:
    第47课 父子间的冲突
    第46课 继承中的构造与析构
    第45课 不同的继承方式
    3.天线-网络规划-网络优化
    2.多址技术
    断剑重铸013
    断剑重铸012
    断剑重铸011
    1.LTE系统概述
    断剑重铸010
  • 原文地址:https://www.cnblogs.com/rainydays/p/2076136.html
Copyright © 2011-2022 走看看