poj3067
求交点的个数;
容易发现,对于两条航线(xi,yi)和(xj,yj),设xi<xj
只有yi>yj时两条航线存在交点;
于是我们考虑以x为第一关键字减序,y为第二关键字为减序排序;
则对于当前航线(xi,yi),只要找之前所有yj小于yi的个数
所有交点数就是其总和,统计就要用到飘逸的树状数组了~
var a,c:array[..] of longint;
x,y:array[..] of longint;
i,j,n,m,k,t:longint;
ans:int64; procedure add(p:longint);
begin
while p<=m do
begin
inc(c[p]);
p:=p+lowbit(p);
end;
end;
function ask(p:longint):longint;
begin
ask:=;
while p<> do
begin
ask:=ask+c[p];
p:=p-lowbit(p);
end;
end;
procedure sort(l,r: longint);
var i,j,h,p: longint;
begin
i:=l;
j:=r;
h:=x[(l+r) div ];
p:=y[(l+r) div ];
repeat
while (x[i]<h) or (x[i]=h) and (y[i]<p) do inc(i);
while (h<x[j]) or (x[j]=h) and (p<y[j]) do dec(j);
if not(i>j) then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; begin
readln(t);
for i:= to t do
begin
readln(n,m,k);
for j:= to k do
readln(x[j],y[j]);
ans:=;
sort(,k);
fillchar(c,sizeof(c),);
fillchar(a,sizeof(a),);
inc(a[y[k]]);
add(y[k]);
for j:=k- downto do
begin
ans:=ans+ask(y[j]-); //这是唯一要注意的细节,交点一定不能在城市处
inc(a[y[j]]);
add(y[j]);
end;
writeln('Test case ',i,': ',ans);
end;
end.
poj3067的更多相关文章
- POJ-3067 Japan---树状数组逆序对变形
题目链接: https://vjudge.net/problem/POJ-3067 题目大意: 日本岛东海岸与西海岸分别有N和M个城市,现在修高速公路连接东西海岸的城市,求交点个数. 解题思路: 记每 ...
- poj3067树状数组求逆序数
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- poj3067 Japan 树状数组求逆序对
题目链接:http://poj.org/problem?id=3067 题目就是让我们求连线后交点的个数 很容易想到将左端点从小到大排序,如果左端点相同则右端点从小到大排序 那么答案即为逆序对的个数 ...
- poj3067 二维偏序树状数组
题解是直接对一维升序排列,然后计算有树状数组中比二维小的点即可 但是对二维降序排列为什么不信呢?? /* */ #include<iostream> #include<cstring ...
- poj-3067(树状数组)
题目链接:传送门 题意:日本有东城m个城市,西城m个城市,东城与西城相互连线架桥,判断这些桥相交的次数. 思路:两个直线相交就是(x1-x2)*(y1-y2)<0,所以,对x,y进行排序,按照x ...
- poj3067 Japan(树状数组)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...
- POJ3067(树状数组:统计数字出现个数)
Japan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 24151 Accepted: 6535 Descriptio ...
- POJ3067 Japan
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26270 Accepted: 7132 Description Japa ...
- POJ3067:Japan(线段树)
Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for th ...
随机推荐
- PHP通过IP 获取 地理位置(实例代码)
发布:JB02 来源:脚本学堂 分享一例php代码,实现通过IP地址获取访问者的地理位置,在php编程中经常用到,有需要的朋友参考下吧.本节内容:PHP通过IP获取地理位置 例子: 复制代码代码示 ...
- 从零学起PHP
数据库连接conn.php <?php //第一步:链接数据库 $conn=@mysql_connect("localhost:3306","root", ...
- (转载)总结一下SQL语句中引号(')、quotedstr()、('')、format()在SQL语句中的用法
总结一下SQL语句中引号(').quotedstr().('').format()在SQL语句中的用法 总结一下SQL语句中引号(').quotedstr().('').format()在SQL语句中 ...
- ARM-Linux S5PV210 UART驱动(6)----platform device的添加
开发板是飞凌OK210 arch/arm/mach-s5pv210/mach-smdkc110.c 首先是UART的寄存器默认配置信息: /* Following are default values ...
- Python+PyQt 数据库基本操作
Sqlite: 使用Python的sqlite3: 需要注意下commit方式与qt稍有不同 import sqlite3 class DBManager(): def __init__(self): ...
- CodeForces 18C
Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...
- Javacript 客户端保存数据[ locaStorage ]
1.通常程序员们会使用Cookie进行一些小量的数据储存在客户端浏览器,但孰不知这样会造成不必要的带宽浪费 ,可使用 js 中的 locaStorage 来替代cookie进行存储,但不支持IE8以下 ...
- 机器学习基石的泛化理论及VC维部分整理(第五讲)
第五讲 Training versus Testing 一.问题的提出 \(P_{\mathcal{D}}\left [ BAD \mathcal{D} \right ] \leq 2M \cd ...
- 1045: [HAOI2008] 糖果传递 - BZOJ
Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1.Input 小朋友个数n 下面n行 aiOutput 求使所有人获得均等糖果的 ...
- 4.1 spring-alias 标签的解析;
对于之前漫长的,最核心的Bean标签的解析就没什么好讲的了, 首先看看使用方法: <bean id="car" name="cat0" class=&qu ...