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 ...
随机推荐
- 项目有叉号, 但是没有代码错误的时候, 是JDK版本的问题
windows---proferences---java--compiler进入项目--properties---java Compiler进入项目--properties---Myeclipse-- ...
- lsof使用
用netstat命令去统计服务器目前的网络连接状态 netstat -n|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' netstat - ...
- jQuery 设置select默认选中问题
在进行其他操作后,恢复select默认选中 html代码: <select id="shai" style="width:150px;margin:5px 50px ...
- kali rolling 安装typecho
#1 apt-get install nginx php7.0 php7.0-mysql php7.0-gd php7.0-cgi php7.0-cli php7.0-curl php7.0-fpm ...
- C/C++中define定义的常量与const常量
常量是在程序中不能更改的量,在C/C++中有两种方式定义常量,一种是利用define宏定义的方式,一种是C++中新提出来的const型常变量,下面主要讨论它们之间的相关问题: define定义的常量: ...
- C/C++中整数与浮点数在内存中的表示方式
在C/C++中数字类型主要有整数与浮点数两种类型,在32位机器中整型占4字节,浮点数分为float,double两种类型,其中float占4字节,而double占8字节.下面来说明它们在内存中的具体表 ...
- 解决ubuntu下的firefox无法在线播放音频和视频的问题
一贯无视 Linux 平台的腾讯(无贬义)理所当然地没有开发QQ音乐Linux版,于是想尝试QQ音乐网页版,结果发现歌曲无法播放.刚开始以为是腾讯还在网页版上用万恶的 Windows Media Pl ...
- push类型消息中间件-消息服务端(三)
1.连接管理 网络架构原来是使用是自己开发的网络框架Gecko,Gecko默认为每个网络连接分配64KB的内存,支持1000个网络连接,就需要大概64MB的内存.后来采用Netty重构了网络服务层. ...
- Linux用户相关的操作命令
1.建用户: adduser phpq //新建phpq用户 passwd phpq //给phpq用户设置密码 2.建工作组 groupadd test //新建 ...
- 永久修改python默认的字符编码为utf-8
这个修改说来简单,其实不同的系统,修改起来还真不一样.下面来罗列下3中情况 首先所有修改的动作都是要创建一个叫 sitecustomize.py的文件,为什么要创建这个文件呢,是因为python在启动 ...