E. The Best among Equals
Posted stupid_one
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; }
以上是关于E. The Best among Equals的主要内容,如果未能解决你的问题,请参考以下文章
E. Madoka and The Best University(数论&gcd)
Transitions Among the Processor’s Operating Modes
Codeforces Global Round 19 E. Best Pair
Codeforces Global Round 19 E. Best Pair
docker could not find an available, non-overlapping IPv4 address pool among the defaults to assign t
Java hashCode() and equals() – Contract, rules and best practices