codeforces 98 div2 C.History 水题
2 seconds
256 megabytes
standard input
standard output
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.
Everybody knows that the World history encompasses exactly n events: the i-th event had continued from the year ai to the year biinclusive (ai < bi). Polycarpus easily learned the dates when each of n events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event jincludes an event i if aj < ai and bi < bj. Your task is simpler: find the number of events that are included in some other event.
The first input line contains integer n (1 ≤ n ≤ 105) which represents the number of events. Next n lines contain descriptions of the historical events, one event per line. The i + 1 line contains two integers ai and bi (1 ≤ ai < bi ≤ 109) — the beginning and the end of the i-th event. No two events start or finish in the same year, that is, ai ≠ aj, ai ≠ bj, bi ≠ aj, bi ≠ bj for all i, j (where i ≠ j). Events are given in arbitrary order.
Print the only integer — the answer to the problem.
5
1 10
2 9
3 8
4 7
5 6
4
5
1 100
2 50
51 99
52 98
10 60
4
1
1 1000000000
0
题意:给你n歌时间段,开始和结束,找出有多少个时间段在另外任意的时间段内;
思路:所以我们先按结束时间排序,每次更新最小值;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 100000000000005
#define MAXN 10000010
//#pragma comment(linker, "/STACK:102400000,102400000")
struct is
{
int st,en;
bool operator <(const is &x)const
{
if(en!=x.en)
return en>x.en;
return st<x.st;
}
}a[];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
for(i=;i<x;i++)
scanf("%d%d",&a[i].st,&a[i].en);
sort(a,a+x);
int minn=a[].st,maxx=a[].en;
int minnn=a[].st,maxxx=a[].en;
int ans=;
for(i=;i<x;i++)
{
if((maxx>a[i].en&&minn<a[i].st)||(maxxx>a[i].en&&minnn<a[i].st))
ans++;
if(a[i].st<minnn)
{
maxx=maxxx;
minn=minnn;
minnn=a[i].st;
maxxx=a[i].en;
}
}
cout<<ans<<endl;
return ;
}
codeforces 98 div2 C.History 水题的更多相关文章
- codeforces 97 div2 C.Replacement 水题
C. Replacement time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforces 577B B. Modulo Sum(水题)
题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树
A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...
- codeforces 696A Lorenzo Von Matterhorn 水题
这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- Codeforces Gym 100286G Giant Screen 水题
Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...
- codeforces 710A A. King Moves(水题)
题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...
- codeforces 659A A. Round House(水题)
题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForces 489B BerSU Ball (水题 双指针)
B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- java的bean和map互转的工具类
import java.beans.BeanInfo;import java.beans.IntrospectionException;import java.beans.Introspector;i ...
- 170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
报错截图: 原因:搭建项目的时候,springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖. 解决步骤: 1.添加jackson依赖到pom.xml <!-- j ...
- c#字符串切割split使用方法
string strtest = "asdfg12wertgv1287654" "}, StringSplitOptions.RemoveEmptyEntries); 结 ...
- Python爬虫框架Scrapy实例(二)
目标任务:使用Scrapy框架爬取新浪网导航页所有大类.小类.小类里的子链接.以及子链接页面的新闻内容,最后保存到本地. 大类小类如下图所示: 点击国内这个小类,进入页面后效果如下图(部分截图): 查 ...
- Windows:子线程中创建窗口
一般来讲,UI的所有操作都必须在主线程,否则会出现未知错误.但有时候我们会需要一个功能比较单一的窗口,同时希望他在一个单独的线程运行.并不影响主线程的效率. 下面说明一下新建子线程创建的新窗口的方法, ...
- JavaScript原型链的理解
JavaScript中的每一个对象都有prototype属性,我们称之为原型,而原型的值也是一个对象,因此它有自己的原型,这样就串联起来形成了一条原型链.原型链的链头是object,它的prototy ...
- Flex 布局:实例篇
上一篇文章介绍了Flex布局的语法,今天介绍常见布局的Flex写法.你会看到,不管是什么布局,Flex往往都可以几行命令搞定. 我只列出代码,详细的语法解释请查阅<Flex布局教程:语法篇& ...
- Web Services 简介
通过使用 Web Services,您的应用程序可以向全世界发布信息,或提供某项功能.Web Services 脚本平台需支持 XML + HTTP. Web Services 简介 Web Serv ...
- Jmeter之Constant Timer与constant throughput timer的区别
当放置Constant Timer于两个http请求之间,那么它代表的含义是:在上一个请求发出至完成后, 开始Contant Timer指定的时间,最后再发出第二个请求.它并不是代表两个请求之间的发送 ...
- ASP.NET 无法生成临时类(result=1)图解
说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.InvalidOperationExcep ...