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. 脚踏实地学C#3-装箱和拆箱

    装箱:一种接受值类型的值,根据这个值在堆中创建一个完整的引用类型对象并返回对象的引用(堆地址)的隐式转换 int i_number = 2; //在栈中声明int类型i_Number变量并初始化 ob ...

  2. 使用MongoDB.NET 2.2.4驱动版本对 Mongodb3.3数据库中GridFS增删改查

    Program.cs代码如下: internal class Program { private static void Main(string[] args) { GridFSHelper help ...

  3. Android自动化测试怎么填写Xpath

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA5sAAAJYCAIAAABjAmXpAAAgAElEQVR4nOzdeZhb5Z0veNV/M88sz7 ...

  4. BZOJ_5418_[Noi2018]屠龙勇士_exgcd+excrt

    BZOJ_5418_[Noi2018]屠龙勇士_exgcd+excrt Description www.lydsy.com/JudgeOnline/upload/noi2018day2.pdf 每次用 ...

  5. JAVA 需要理解的重点 一

    需要理解的重点内容有: JVM内存管理机制和垃圾回收机制(基本每次面试都会问,一定要搞得透彻) JVM内存调优(了解是怎么回事,一般做项目过程中使用较多) 设计模式(熟悉常见设计模式的应用场景,会画类 ...

  6. 5.oracle中一个字段中存储'a','b'与'a'与a的写法,存储过程中与之对应

    select '''a'',''b''' from dual; --'a','b' select '''a''' from dual; --'a' select 'a' from dual; --a

  7. c++中stl----vector

    1 vector是啥玩意 (1)可以使用下标访问个别的元素 (2)迭代器可以按照不同的方式遍历 (3)可以在容器的末尾增加或者删除元素 2 容器大小和容器的容量区别 (1)大小是元素的个数,容量是分配 ...

  8. 【Data Structure & Algorithm】求子数组的最大和

    求子数组的最大和 题目:输入一个整型数组,数组里有正数和负数.数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和.求所有子数组的和的最大值,要求时间复杂度为O(n).例如输入数组为1, - ...

  9. as3杂记

    一.内存回收方式: 1.引用计数[没有互相引用] 2.标记清除[fp自己检测是否引用,没有引用的清除] 二.通信方式: 1.http:小型页游[charles抓包查看] 2.socket:大型页游[W ...

  10. C# 获取汉字的拼音首字母和全拼(含源码)

    C# 获取汉字的拼音首字母 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手 ...