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. Idea中的插件-列出Java Bean的所有set方法

    插件的git 地址: https://github.com/yoke233/genSets 将插件jar导入idea中,使用方式是对象后加.allset,然后回车.

  2. cowboy中分布式节点通信

    项目开发中,web前端节点需要与远端的聊天服节点通信.聊天服使用了otp,但我对otp下的分布式通信不太清楚,造成了一些问题. 1)首先是cowboy节点的命名.具体参数是配置在工程目录rel下的vm ...

  3. hdu-5742 It's All In The Mind(数学)

    题目链接: It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (J ...

  4. 【C/C++】获取当前系统时间

    #include<iostream> #include<Ctime> using namespace std; int main() { time_t t; time(& ...

  5. atexit函数详解

    对C语言有所了解的人都知道main函数是整个程序的入口,但是其实不然,在内核中可以使用链接器来设置程序的开始地方.当内核使⽤⼀个exec函数执⾏C程序时,在调⽤main函数之前先调⽤⼀个特殊的启动例程 ...

  6. bzoj 2169 连边——去重的思想

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2169 如果之前都去好重了,可以看作这次连的边只会和上一次连的边重复. 可以认为从上上次的状态 ...

  7. 让应用程序支持emoji字符

    自iPhone从iOS 5在输入法中开始支持emoji以来,这些表情符号迅速风靡世界.但是很多Web网站竟然还不!支!持!!! 那怎么才能支持emoji呢?其实代码一行都不用改,因为emoji符号实际 ...

  8. 【旧文章搬运】加载PE文件时IAT的填充时机

    原文发表于百度空间,2011-06-20========================================================================== 大致过程如 ...

  9. 3.16 使用Zookeeper对HDFS HA配置自动故障转移及测试

    一.说明 从上一节可看出,虽然搭建好了HA架构,但是只能手动进行active与standby的切换: 接下来看一下用zookeeper进行自动故障转移: # 在启动HA之后,两个NameNode都是s ...

  10. 网络编程-http连接-GET&POST

    GetRequest package com.net.http; import java.io.BufferedReader; import java.io.IOException; import j ...