zoukankan      html  css  js  c++  java
  • E. The Best among Equals

    http://codeforces.com/gym/101149/problem/E

    这题的话,关键是注意到一定是要max score

    然后就可以选出一个L最大优先,并且R最大的区间,

    扫一次就能得到答案了。

    3
    1 3
    1 3
    4 5

    这组数据,只能是1

    因为max score优先,要选[4,5]这段区间的人。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    const int maxn = 1e6 + 20;
    int arr[maxn];
    int L[maxn];
    int R[maxn];
    int book[maxn];
    void work() {
        int n;
        cin >> n;
        int lenarr = 0;
        for (int i = 1; i <= n; ++i) {
            cin >> L[i] >> R[i];
            if (L[i] > R[i]) swap(L[i], R[i]);
            arr[++lenarr] = L[i];
            arr[++lenarr] = R[i];
        }
        int mx = -inf;
        int id = inf;
        for (int i = 1; i <= n; ++i) {
            if (mx < L[i]) {
                mx = L[i];
                id = i;
            } else if (mx == L[i]) {
                if (R[id] < R[i]) {
                    id = i;
                }
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (R[i] < L[id]) continue;
            ans++;
        }
        cout << ans << endl;
    //    sort(arr + 1, arr + 1 + lenarr);
    //    for (int i = 1; i <= n; ++i) {
    //        int hash_L = lower_bound(arr + 1, arr + 1 + lenarr, L[i]) - arr;
    //        int hash_R = lower_bound(arr + 1, arr + 1 + lenarr, R[i]) - arr;
    ////        cout << hash_L << " " << hash_R << endl;
    //        book[hash_L]++;
    //        book[hash_R + 1]--;
    //    }
    //    int ans = 0;
    //    int begin = lower_bound(arr + 1, arr + 1 + lenarr, L[id]) - arr;
    //    int end = lower_bound(arr + 1, arr + 1 + lenarr, R[id]) - arr;
    //    for (int i = 1; i <= lenarr + 1; ++i) {
    //        book[i] += book[i - 1];
    //        if (i >= begin && i <= end)
    //            ans = max(book[i], ans);
    //    }
    //    cout << ans << endl;
    }
    
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        IOS;
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    pom.xml基础配置
    Maven零散笔记——配置Nexus
    搭建局域网maven仓库
    java 加密解密
    菠萝大象--sping
    (转)Spring对注解(Annotation)处理源码分析1——扫描和读取Bean定义
    eclipse 如何把java项目转成web项目
    Effective Java
    More Effective C++
    Effective C++
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6036992.html
Copyright © 2011-2022 走看看