zoukankan      html  css  js  c++  java
  • UVA-11020(BST)

    题意:

    给n个点,一个点(x,y)有优势时满足不存在点(fx,fy)使得fx<x,fy<=y或fx<=x,fy<y;问当前有多少个有优势点;

    思路:

    学习BST的入门题,代码是白书上的;

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    #include <map>
     
    using namespace std;
     
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
     
    typedef  long long LL;
     
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
     
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9+10;
    const int N=1e5+10;
    const int maxn=1e3+20;
    const double eps=1e-12;
    
    
    struct PO
    {
        int x,y;
        bool operator< (const PO& rhs) const
        {
            return x<rhs.x||(x==rhs.x&&y<rhs.y);
        }
    };
    multiset<PO>s;
    multiset<PO>::iterator it;
    int main()
    {
        int t,Case=0;
        read(t);
        while(t--)
        {
            s.clear();
            if(Case)printf("
    ");
            printf("Case #%d:
    ",++Case);
            int n,x,y;
            read(n);
            For(i,1,n)
            {
                read(x);read(y);
                PO temp=(PO){x,y};
                it=s.lower_bound(temp);
                if(it == s.begin()||(--it)->y > y)
                {
                    s.insert(temp);
                    it=s.upper_bound(temp);
                    while(it!=s.end()&&it->y >= y)s.erase(it++);
                }
                printf("%d
    ",s.size());
            }
        }
        return 0;
    }
    

      

  • 相关阅读:
    主键、外键和索引的区别
    设置session超时的三种方式
    redis常用操作
    timestamp 转 date 处理后再转timestamp
    fragment在水平/垂直时的应用
    Activity堆栈管理
    ORMLite的使用
    onItemLongClick事件的监听
    Bundle的使用
    有关implicit Intent的使用
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5794749.html
Copyright © 2011-2022 走看看