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. 将PHP数组输出为HTML表格

    1. [代码][PHP]代码    <?phpclass xtable{    private $tit,$arr,$fons,$sextra;    public function __con ...

  2. Spring源码-加载和IOC部分

    源代码和注释放在了github上,包括加载过程的注释和getBean部分的 地址: https://github.com/lvxingzhi/spring-framework-4.3.9-note.g ...

  3. tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用——模型层次太深,或者太复杂训练时候都不会收敛

    tflearn 中文汉字识别,训练后模型存为pb给TensorFlow使用. 数据目录在data,data下放了汉字识别图片: data$ ls0  1  10  11  12  13  14  15 ...

  4. MySQL丨5.6版本插入中文显示问号解决方法

    解决办法: 1.找到安装目录下的my-default.ini 这个配置文件 2.copy一份粘贴到同目录下 另命名为my.ini 3.在my.ini 配置下加上下面几句代码 并保存 [mysql]de ...

  5. css 内容超出宽度自动换行

    1. word-break:break-all;只对英文起作用,以字母作为换行依据2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 PS:要设定宽度!

  6. ComboBox的真实值和显示值

    一.类型 /// <summary> /// 下拉框值类型 /// </summary> public class TextAndValue { /// <summary ...

  7. dockerfile_nginx+PHP+mongo数据库_完美搭建

      基于dockerfile创建nginx+PHP+mongo数据库_完美搭建     第一步:   从git上:git clone http://git.oursdata.com/wangyue/d ...

  8. 【旧文章搬运】Win7 OBJECT_HEADER之TypeIndex解析

    原文发表于百度空间,2010-08-09========================================================================== 在Wind ...

  9. 在调试javascript的时候,要常使用alert()

    在调试javascript的时候,要常使用alert()会帮助我们定位脚本错误.

  10. 3.4-3.6 依据业务需求分析HBase的表设计

    一.依据[话单]查询需求分析HBase的表设计 1.分析 用户需要进行实时的查询,那么这些数据是放在HBase当中的,每个客户每天接打电话至少20个左右,而通信公司拥有很多用户,每天产生的数据都是上亿 ...