zoukankan      html  css  js  c++  java
  • UESTC 电子科大专题训练 数据结构 D

    UESTC 1584

    题意:平面坐标上有n个怪物,每个怪物有一个rank值,代表x坐标和y坐标都不大于它本身的怪物数(不包括本身)

    思路:对x y坐标从小到大排序,x优先排序,用数状数组计算y坐标小于它的数量

    AC代码:

    #include "iostream"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #define ll long long
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a) memset(a,0,sizeof(a))
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    using namespace std;
    const long long INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const int N=1e5+100;
    const ll mod=1e9+7;
    
    struct Point{
        int x, y;
        bool friend operator< (Point a, Point b){
            if(a.x==b.x) return a.y<b.y;
            return a.x<b.x;
        }
    };
    Point P[N];
    int n,ma,Y[N],ans[N];
    int lowbit(int x){
        return (-x)&x;
    }
    void add(int y, int num){
        while(y<=ma){
            Y[y]+=num;
            y+=lowbit(y);
        }
    }
    int sum(int y){
        int ret=0;
        while(y>0){
            ret+=Y[y];
            y-=lowbit(y);
        }
        return ret;
    }
    int main(){
        //ios::sync_with_stdio(false),cin.tie(0);cout.tie(0);
        cin>>n;
        for(int i=1; i<=n; ++i){
            cin>>P[i].x>>P[i].y;
            ma=max(ma,P[i].y), ma=max(ma,P[i].y);
        }
        sort(P+1,P+1+n);
        for(int i=1; i<=n; ++i){
            int cnt=sum(P[i].y);
            ans[cnt]++;
            add(P[i].y,1);
        }
        for(int i=0; i<n; ++i){
           cout<<ans[i]<<"
    ";
        }
        return 0;
    }
  • 相关阅读:
    sqhhb
    12333
    12

    今日份
    12
    彻底理解 Cookie、Session、Token
    https原理
    12312
    uiower
  • 原文地址:https://www.cnblogs.com/max88888888/p/7223172.html
Copyright © 2011-2022 走看看