zoukankan      html  css  js  c++  java
  • 牛客练习赛4 A Laptop

    传送门:https://ac.nowcoder.com/acm/contest/16/A

    题意:

    每个物品有2个属性,求有多少个物品的两个属性完全小于另一个物品

    题解:

    求逆序对板子题

    代码:

    /**
     *        ┏┓    ┏┓
     *        ┏┛┗━━━━━━━┛┗━━━┓
     *        ┃       ┃  
     *        ┃   ━    ┃
     *        ┃ >   < ┃
     *        ┃       ┃
     *        ┃... ⌒ ...  ┃
     *        ┃       ┃
     *        ┗━┓   ┏━┛
     *          ┃   ┃ Code is far away from bug with the animal protecting          
     *          ┃   ┃   神兽保佑,代码无bug
     *          ┃   ┃           
     *          ┃   ┃        
     *          ┃   ┃
     *          ┃   ┃           
     *          ┃   ┗━━━┓
     *          ┃       ┣┓
     *          ┃       ┏┛
     *          ┗┓┓┏━┳┓┏┛
     *           ┃┫┫ ┃┫┫
     *           ┗┻┛ ┗┻┛
     */
    // warm heart, wagging tail,and a smile just for you!
    //
    //                            _ooOoo_
    //                           o8888888o
    //                           88" . "88
    //                           (| -_- |)
    //                           O  =  /O
    //                        ____/`---'\____
    //                      .'  |     |//  `.
    //                     /  |||  :  |||//  
    //                    /  _||||| -:- |||||-  
    //                    |   | \  -  /// |   |
    //                    | \_|  ''---/''  |   |
    //                      .-\__  `-`  ___/-. /
    //                  ___`. .'  /--.--  `. . __
    //               ."" '<  `.___\_<|>_/___.'  >'"".
    //              | | :  `- \`.;` _ /`;.`/ - ` : | |
    //                 `-.   \_ __ /__ _/   .-` /  /
    //         ======`-.____`-.___\_____/___.-`____.-'======
    //                            `=---='
    //        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //                     佛祖保佑      永无BUG
    #include <set>
    #include <map>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <ctime>
    #include <bitset>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    typedef long long LL;
    typedef pair<LL, LL> pLL;
    typedef pair<LL, int> pLi;
    typedef pair<int, LL> pil;;
    typedef pair<int, int> pii;
    typedef unsigned long long uLL;
    #define ls rt<<1
    #define rs rt<<1|1
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define bug printf("*********
    ")
    #define FIN freopen("input.txt","r",stdin);
    #define FON freopen("output.txt","w+",stdout);
    #define IO ios::sync_with_stdio(false),cin.tie(0)
    #define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]
    "
    #define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]
    "
    #define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]
    "
    
    const double eps = 1e-8;
    const int mod = 1e9 + 7;
    const int maxn = 3e5 + 5;
    const int INF = 0x3f3f3f3f;
    const LL INFLL = 0x3f3f3f3f3f3f3f3f;
    struct node {
        int m, v;
        bool operator < (const node &a) const {
            return m < a.m;
        }
    } a[maxn];
    vector<int> vec;
    int n;
    int bit[maxn];
    int lowbit(int x) {
        return x & -x;
    }
    void add(int pos, int x) {
        while(pos <= n) {
            bit[pos] += x;
            pos += lowbit(pos);
        }
    }
    int sum(int pos) {
        int ans = 0;
        while(pos) {
            ans += bit[pos];
            pos -= lowbit(pos);
        }
        return ans;
    }
    int main() {
    #ifndef ONLINE_JUDGE
        FIN
    #endif
        scanf("%d", &n);
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &a[i].m, &a[i].v);
            vec.push_back(a[i].v);
        }
        sort(a + 1, a + n + 1);
        sort(vec.begin(), vec.end());
        vec.erase(unique(vec.begin(), vec.end()), vec.end());
        int ans = 0;
        for(int i = n; i >= 1; i--) {
            int pos = lower_bound(vec.begin(), vec.end(), a[i].v) - vec.begin() + 1;
            if((n - i ) - sum(pos)) {
                ans++;
            }
            add(pos, 1);
        }
        printf("%d
    ", ans);
    
        return 0;
    }
    
    每一个不曾刷题的日子 都是对生命的辜负 从弱小到强大,需要一段时间的沉淀,就是现在了 ~buerdepepeqi
  • 相关阅读:
    PHP unicode与普通字符串的相互转化
    PHP 日期之间所有日期
    PHP Excel导入日期单元格处理
    JS base64文件转化blob文件
    Mvc 刷新PartialView
    WebGL绘制变幻光斑
    WebGL笔记(四):初步封装
    WebGL笔记(目录)
    [JavaScript/canvas] 创建基于坐标访问的图形数据对象
    WebGL笔记(五):封装顶点和颜色等数组数据(二)
  • 原文地址:https://www.cnblogs.com/buerdepepeqi/p/10852889.html
Copyright © 2011-2022 走看看