POJ 3416 Crossing
树状数组+离线操作
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std; int N,M;
int SUM1,SUM2,SUM3,SUM4;
int C[+]; struct Point
{
int x,y,PD,ans,id,BiX,BiY;
} point[*+]; int Lowbit(int x)
{
return x&(-x);
} int GetSum(int End)
{
int sum=;
while(End>)
{
sum=sum+C[End];
End=End-Lowbit(End);
}
return sum;
} void Update(int Start,int num)
{
while(Start<+)
{
C[Start]=C[Start]+num;
Start=Start+Lowbit(Start);
}
} bool cmpPointX(const Point&a,const Point&b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
} bool cmpPointY(const Point&a,const Point&b)
{
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
} bool cmpID(const Point&a,const Point&b)
{
return a.id<b.id;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,j;
scanf("%d%d",&N,&M);
memset(C,,sizeof(C));
for(i=; i<N; i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
point[i].PD=;
point[i].x++;
point[i].y++;
point[i].id=-;
}
for(i=N; i<N+M; i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
point[i].id=i;
point[i].PD=;
point[i].x++;
point[i].y++;
}
int tot=;
sort(point,point+N+M,cmpPointX);
for(i=;i<N+M;i++)
if(point[i].PD)
point[i].BiX=i-tot,tot++;
tot=;
sort(point,point+N+M,cmpPointY);
for(i=;i<N+M;i++)
if(point[i].PD)
point[i].BiY=i-tot,tot++;
for(i=;i<N+M;i++)
{
if(!point[i].PD) Update(point[i].x,);
else
{
SUM2=GetSum(point[i].x);
SUM1=point[i].BiY-SUM2;
SUM3=point[i].BiX-SUM2;
SUM4=N-SUM1-SUM2-SUM3;
point[i].ans=SUM1+SUM3-SUM2-SUM4;
}
}
sort(point,point+N+M,cmpID);
for(i=; i<N+M; i++)
if(point[i].PD)
printf("%d\n",max(point[i].ans,-point[i].ans));
printf("\n");
}
return ;
}
POJ 3416 Crossing的更多相关文章
- POJ 3416 Crossing --离线+树状数组
题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...
- POJ 1700 Crossing River (贪心)
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9585 Accepted: 3622 Descri ...
- poj 1700 Crossing River 过河问题。贪心
Crossing River Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9887 Accepted: 3737 De ...
- poj 1700 Crossing River C++/Java
http://poj.org/problem?id=1700 题目大意: 有n个人要过坐船过河,每一个人划船有个时间a[i],每次最多两个人坐一条船过河.且过河时间为两个人中速度慢的,求n个人过河的最 ...
- POJ 1700 - Crossing River
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13982 Accepted: 5349 Description A gr ...
- ACM学习历程——POJ 1700 Crossing River(贪心)
Description A group of N people wishes to go across a river with only one boat, which can at most ca ...
- Crossing River POJ过河问题
A group of N people wishes to go across a river with only one boat, which can at most carry two pers ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
随机推荐
- 自己通过反射写的一个属性copy类
package com.xxx.beancopier; import java.lang.annotation.Documented; import java.lang.annotation.Elem ...
- @property (nonatomic, getter = isExpanded) BOOL expanded;
如果这个property是 BOOL on, 那么Objc默认创建的 setter 为: - (void)on:(BOOL)setOn { } getter 为: - (BOOL)on { retur ...
- linux(centos7)下SVN服务器如何搭建
linux(centos)下SVN服务器如何搭建?说到SVN服务器,想必大家都知道,可以是在LINUX下如何搭建SVN服务器呢?那么今天给大家分享一下linux(centos)搭建SVN服务器的思路! ...
- JSP脚本元素、指令元素、动作元素
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- Linux关闭selinux
最近在折腾Linux服务器,配置环境时,安装php的一个拓展,明明编译成功了,就是加载不进去,phpinfo不显示,查看错误日志是显示加载失败,没权限==,配置ftp程序也会有意想不到的问题,搞了好久 ...
- 【第三篇】Volley图片加载之NetworkImageView代码分析
在Volley的使用之加载图片讲过使用NetWorkImageView进行图片加载的例子,本文着重讲解NetWorkImageView内部是如何实现的,以及Volley这个控件有什么特性. 1,通 ...
- ListView的条目点击焦点的问题
由于ListView条目里有ImageButton,导致抢占了条目点击事件,所以在item的跟布局中加入 android:descendantFocusability="blocksDesc ...
- Struts2-3.struts.xml的action可以简写
如果只是跳转到某个页面的话,可以这样写 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE s ...
- Linq使用方法
int pollid = poll.Where(f => f.PollID < CurrentId).OrderByDescending(o => o.PollID).FirstOr ...
- web页面开发相关基础
CSS是一种用于web的标准布局语言,可以控制版面.颜色以及元素和图像的大小和位置.HTML文档应该利用外部样式表来定义文档中使用的样式.JavaScript也应该放在外部文档中,这个文档应该只包含J ...