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]这段区间的人。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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; }
既然选择了远方,就要风雨兼程~
posted on 2016-11-07 00:08 stupid_one 阅读(343) 评论(0) 编辑 收藏 举报