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 ...
随机推荐
- hadoop filesystem 删除文件 复制文件 重命名文件
private void moveFile(Configuration conf, String Path1, String Path2, String newname ) throws IOExce ...
- git操作技巧(转载)
转载自:https://segmentfault.com/q/1010000000181403 git支持很多种工作流程,我们采用的一般是这样,远程创建一个主分支,本地每人创建功能分支,日常工作流程如 ...
- XSS前端防火墙
前一段时间,在EtherDream大神的博客里看到关于XSS防火墙的一系列文章,觉得很有意思.刚好科创要做一个防火墙,就把XSS前端防火墙作为一个创新点,着手去实现了. 在实现过程中,由于各种原因,比 ...
- linux 命令 备忘
openssl rand -base64 32 随机数 date | md5sum data 日期 cal 日历 man -f man sync 数据同步写入磁盘 shutdown reboot ha ...
- ExtJS4.2学习(三)Grid表格(转)
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-07/172.html --------------- ...
- js数组反转
var _li = test.getElementsByTagName("li"), arrayObj = [].slice.apply(_li),//_li用apply调用sli ...
- ITQ迭代量化方法解析
一.问题来源 来源于换关键字,从LSH转换为hash检索,这要感谢李某. 二.解析 笔者认为关键思想是数据降维后使用矩阵旋转优化,其他和LSH一样的. 2.1 PCA降维 先对原始空间的数据集 X∈R ...
- PAT-乙级-1024. 科学计数法 (20)
1024. 科学计数法 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HOU, Qiming 科学计数法是科学家用来表示很 ...
- PAT-乙级-1016. 部分A+B (15)
1016. 部分A+B (15) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 正整数A的“DA(为1位整数)部 ...
- spoj 346
当一个数大于等于12 那分别处以2, 3, 4之后的和一定大于本身 但是直接递归会超时 然后发现有人用map存了 膜拜..... #include <cstdio> #i ...