【离散化扫描】 校门外的树{加强版}
来源:互联网 发布:淘宝店铺logo制作 编辑:程序博客网 时间:2024/05/21 06:18
校门外的树
某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米。我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置;数轴上的每个整数点,即0,1,2,……,L,都种有一棵树。
由于马路上有一些区域要用来建地铁。这些区域用它们在数轴上的起始点和终止点表示。已知任一区域的起始点和终止点的坐标都是整数,区域之间可能有重合的部分。现在要把这些区域中的树(包括区域端点处的两棵树)移走。你的任务是计算将这些树都移走后,马路上还有多少棵树。
输入格式
输入文件tree.in的第一行有两个整数L、M,L代表马路的长度,M代表区域的数目,L和M之间用一个空格隔开。接下来的M行每行包含两个不同的整数,用一个空格隔开,表示一个区域的起始点和终止点的坐标。
输出格式
输出文件tree.out包括一行,这一行只包含一个整数,表示马路上剩余的树的数目。
输入样例
500 3
150 300
100 200
470 471
输出样例
298
数据范围:
1 <= L <= 1000000, 1 <= M <= 10000
==============================
=====================
type node=record x,y:longint; end;var l,m:longint; a:array[1..10000]of node;procedure init;begin assign(input,'tree.in'); assign(output,'tree.out'); reset(input); rewrite(output);end;procedure terminate;begin close(input); close(output); halt;end;procedure qsort(s,t:longint);var i,j:longint; x,tem:node;begin i:=s; j:=t; x:=a[(s+t)shr 1]; repeat while (x.x<a[j].x)or((x.x=a[j].x)and(x.y>a[j].y)) do dec(j); while (a[i].x<x.x)or((x.x=a[i].x)and(a[i].y>x.y)) do inc(i); if i<=j then begin tem:=a[i]; a[i]:=a[j]; a[j]:=tem; inc(i); dec(j); end; until i>j; if i<t then qsort(i,t); if s<j then qsort(s,j);end;procedure main;var i:longint; tot:longint; last:longint;begin readln(l,m); for i:=1 to m do readln(a[i].x,a[i].y); qsort(1,m); inc(l); tot:=a[1].y-a[1].x+1; last:=a[1].y; for i:=2 to m do begin if a[i].x<=last then begin if a[i].y>last then begin tot:=tot+a[i].y-last; last:=a[i].y; end; end else begin tot:=tot+a[i].y-a[i].x+1; last:=a[i].y; end; end; writeln(l-tot);end;begin init; main; terminate;end.
- 【离散化扫描】 校门外的树{加强版}
- 校门外的树 数据加强版
- 校门外的树加强版
- noip2005 校门外的树 (离散化处理区间并)
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树
- 校门外的树!
- 校门外的树
- 校门外的树
- dll的两种调用方式
- Weblogic WLDF性能监控使用样例
- android命令总结
- Oracle Connect By Prior用法(实现递归查询)
- 把遇到过的对.Net线程的一些问题和误解集中起来和大家分享,也希望大家能一起补充,热烈欢迎讨论
- 【离散化扫描】 校门外的树{加强版}
- oracle 循环语句总结(break&continue)
- asp.net生成柱状图
- 海量数据查询
- Java动态代理简单实现
- GetAsyncKeyState()和GetKeyboardState()
- 基于移动平台的多媒体框架——序
- JAVA中UDP 接受与发送数据的初步步骤
- oracle connect by prior 树形结构