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 + ;
int arr[maxn];
int L[maxn];
int R[maxn];
int book[maxn];
void work() {
int n;
cin >> n;
int lenarr = ;
for (int i = ; 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 = ; 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 = ;
for (int i = ; 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 ;
}

E. The Best among Equals的更多相关文章

  1. equals变量在前面或者在后面有什么区别吗?这是一个坑点

    我就不废话那么多,直接上代码: package sf.com.mainTest; public class Test { public static void main(String[] args) ...

  2. How to implement equals() and hashCode() methods in Java[reproduced]

    Part I:equals() (javadoc) must define an equivalence relation (it must be reflexive, symmetric, and ...

  3. 【特种兵系列】String中的==和equals()

    1. 小样示例 public static void main(String[] args) { String a = "a" + "b" + 123; Str ...

  4. (转)浅谈Java中的equals和==

    原文地址: http://www.cnblogs.com/dolphin0520/p/3592500.html 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new S ...

  5. 浅谈Java中的equals和==(转)

    浅谈Java中的equals和== 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str ...

  6. List<T>Find方法,FindAll方法,Contains方法,Equals方法

    假如传入的T是一个类, List<MessageInfos> MessageInfos = new List<MessageInfos>(); MessageInfos= Me ...

  7. 让代码重构渐行渐远系列(3)——string.Equals取代直接比较与非比较

    重构背景及原因 最近由于项目组的人员在不断扩充,导致项目中代码风格各异,大有百花齐放甚至怒放之势.考虑到团队的生存与发展,经过众人多次舌战之后,最终决定项目组根据业务分成几个小分队,以加强团队管理与提 ...

  8. [java] 更好的书写equals方法-汇率换算器的实现(4)

    [java] 更好的书写equals方法-汇率换算器的实现(4) // */ // ]]>   [java] 更好的书写equals方法-汇率换算器的实现(4) Table of Content ...

  9. Equals和ReferenceEquals

    稍微分析下一下两个方法的区别: public static bool Equals(object objA, object objB); public static bool ReferenceEqu ...

  10. 【原创】Java和C#下String类型中的==和equals的原理与区别

    一.Java下 1.几个例子 public static void main(String[] arge) { String str1 = new String("1234"); ...

随机推荐

  1. 渗透模型 Percolation Models(一个物理模型的广泛应用)

    转自:http://mooc.guokr.com/note/15357/ http://mooc.guokr.com/user/0298406005/note/ 模型思想: 有水流下来,是否会渗入地面 ...

  2. 关于Ajax实现的简单示例

    一.代码示例 关于Ajax的基本概念(包括XMLHttpRequest对象及其相关方法属性)移步这里(w3school中文版)学习了解. <!doctype html> <html ...

  3. ffmpeg 中av_rescale_rnd 的含义

    http://blog.csdn.net/fireroll/article/details/8485482 一.函数声明: int64_t av_rescale_rnd(int64_t a, int6 ...

  4. 关于URL编码的一些结论

    转载自:http://www.ruanyifeng.com/blog/2010/02/url_encoding.html与http://www.ruanyifeng.com/blog/2007/10/ ...

  5. codeforces 701C C. They Are Everywhere(尺取法)

    题目链接: C. They Are Everywhere time limit per test 2 seconds   memory limit per test 256 megabytes inp ...

  6. D3.JS V4 绘制中国地图

    参考:http://bl.ocks.org/almccon/fe445f1d6b177fd0946800a48aa59c71 http://blog.csdn.net/lzhlzz/article/d ...

  7. Keras 可视化 model

    参考:https://keras.io/visualization/ error解决参考:http://blog.csdn.net/wangjian1204/article/details/50346 ...

  8. Python: PS滤镜--径向模糊

    本文用 Python 实现 PS 滤镜中的径向模糊特效,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/3 ...

  9. HttpClient入门教程

    HttpClient使用详解与实战一:https://www.jianshu.com/p/375be5929bed

  10. Spring 注释标签@Resource @Autowired 和@Inject的区别

    一些spring的开发人员在使用这三个标签进行注入的时候感到困惑.我来尝试解释一下这三个注解的主要区别.事实上,这三者非常相似,只存在一些微小的差别.在稍后的文章中会进行解释. @Resource-在 ...