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]这段区间的人。
#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的更多相关文章
- equals变量在前面或者在后面有什么区别吗?这是一个坑点
我就不废话那么多,直接上代码: package sf.com.mainTest; public class Test { public static void main(String[] args) ...
- 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 ...
- 【特种兵系列】String中的==和equals()
1. 小样示例 public static void main(String[] args) { String a = "a" + "b" + 123; Str ...
- (转)浅谈Java中的equals和==
原文地址: http://www.cnblogs.com/dolphin0520/p/3592500.html 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new S ...
- 浅谈Java中的equals和==(转)
浅谈Java中的equals和== 在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str ...
- List<T>Find方法,FindAll方法,Contains方法,Equals方法
假如传入的T是一个类, List<MessageInfos> MessageInfos = new List<MessageInfos>(); MessageInfos= Me ...
- 让代码重构渐行渐远系列(3)——string.Equals取代直接比较与非比较
重构背景及原因 最近由于项目组的人员在不断扩充,导致项目中代码风格各异,大有百花齐放甚至怒放之势.考虑到团队的生存与发展,经过众人多次舌战之后,最终决定项目组根据业务分成几个小分队,以加强团队管理与提 ...
- [java] 更好的书写equals方法-汇率换算器的实现(4)
[java] 更好的书写equals方法-汇率换算器的实现(4) // */ // ]]> [java] 更好的书写equals方法-汇率换算器的实现(4) Table of Content ...
- Equals和ReferenceEquals
稍微分析下一下两个方法的区别: public static bool Equals(object objA, object objB); public static bool ReferenceEqu ...
- 【原创】Java和C#下String类型中的==和equals的原理与区别
一.Java下 1.几个例子 public static void main(String[] arge) { String str1 = new String("1234"); ...
随机推荐
- haproxy参数解析
HAProxy工作于隧道模式,其仅检查每一个连接的第一个请求, 1. option abortonclose #当服务器负载过高时,将自动关闭队列中处理时间较长的连接请求 2. option http ...
- Linux GCC常用命令学习
1简介 GCC 的意思也只是 GNU C Compiler 而已.经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言:它现在还支持 Ada 语言.C++ 语言.Java 语言.Objective ...
- BZOJ_3231_[Sdoi2008]递归数列_矩阵乘法
BZOJ_3231_[Sdoi2008]递归数列_矩阵乘法 Description 一个由自然数组成的数列按下式定义: 对于i <= k:ai = bi 对于i > k: ai = c1a ...
- Spring 事务管理高级应用难点剖析: 第 1 部分
Spring 的事务管理是被使用得最多的功能之一,虽然 Spring 事务管理已经帮助程序员将要做的事情减到了最小.但在实际开发中,如果使用不当,依然会造成数据连接泄漏等问题.本系列以实际应用中所碰到 ...
- HDU2444(二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- ubuntu解决挂起后不能唤醒
安装 laptop-mode 如果你不缺认自已是否安装了laptop-mode-tools工具包,可以在终端中输入下列命令来确认是否安装. dpkg -l | grep laptop-mode-too ...
- Module:template
ylbtech-Module: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtech. ...
- 类似懒加载的js功能
<!-- 显示15条数据 --> <ul class="list" pagesize="15"> <li> <div ...
- 如何在ubuntu下使用windows下的程序(eg: .exe)
为了在ubutu下安装百度云管家,上网查了下如何在ubuntu 下安装.exe文件,其中遇到一些问题记录如下: 使用的命令: 开始时直接使用的sudo apt-get install wine 在运行 ...
- web.xml报错Cannot resolve class 'StrutsPrepareAndExecuteFilter' (idea创建SSH项目)
原因: xwork-core.jar包已经合并到struts2-core.jar下,并且点开jar包,发现没有 org.apache.struts2.dispatcher.ng.filter.Stru ...