二分点所在区域,叉积判断左右

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=1005;
int T,n,m,x1,y1,x2,y2,ans[N],cnt[N];
struct dian
{
double x,y;
dian(double X=0,double Y=0)
{
x=X,y=Y;
}
dian operator + (const dian &a) const
{
return dian(x+a.x,y+a.y);
}
dian operator - (const dian &a) const
{
return dian(x-a.x,y-a.y);
}
};
struct bian
{
dian s,t;
bian(dian S=dian(),dian T=dian())
{
s=S,t=T;
}
}q[N];
bool cmp(const bian &a,const bian &b)
{
return a.s.x<b.s.x||(a.s.x==b.s.x&&a.t.x<b.t.x);
}
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
double cj(dian a,dian b)
{
return a.x*b.y-a.y*b.x;
}
int main()
{
while(scanf("%d",&n)&&n)
{
memset(ans,0,sizeof(ans));
memset(cnt,0,sizeof(cnt));
m=read(),x1=read(),y1=read(),x2=read(),y2=read();
for(int i=0;i<n;i++)
{
int u=read(),l=read();
q[i]=bian(dian(u,y1),dian(l,y2));
}
q[n]=bian(dian(x2,y1),dian(x2,y2));
sort(q,q+1+n,cmp);
for(int i=1;i<=m;i++)
{
int x=read(),y=read();
dian p=dian(x,y);
int l=0,r=n,ans;
while(l<=r)
{
int mid=(l+r)>>1;
if(cj(q[mid].s-p,q[mid].t-p)<0)
{
ans=mid;
r=mid-1;
}
else
l=mid+1;
}
cnt[ans]++;
}
for(int i=0;i<=n;i++)
ans[cnt[i]]++;
puts("Box");
for(int i=1;i<=m;i++)
if(ans[i])
printf("%d: %d\n",i,ans[i]);
}
return 0;
}

poj 2398 Toy Storage【二分+叉积】的更多相关文章

  1. POJ 2398 Toy Storage 二分+叉积

    Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...

  2. POJ 2398 Toy Storage (叉积判断点和线段的关系)

    题目链接 Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4104   Accepted: 2433 ...

  3. POJ 2398 Toy Storage(叉积+二分)

    Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...

  4. poj 2398 Toy Storage(计算几何)

    题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...

  5. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  6. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  7. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

  8. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  9. POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

  10. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

随机推荐

  1. IdHttp 资料

    http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...

  2. POJ 1780 【手工递归】【欧拉回路】

    题意: 1.提供密码的位数. 2.密码的输入可以一直保持,取后n位作为密码.如果密码正确则开锁. 3.设计一种方法使得在输入最少的情况下破译.(即保证每个密码只输入一次) 4.输出输入的数字的序列. ...

  3. html5摇一摇代码优化

    首先对DeviceMotionEvent进行优化: 去除没用的代码,又一次封装DeviceMotionEven if(window.DeviceMotionEvent) { var speed = 2 ...

  4. MySQL基础笔记(二) 完整性约束

    我们知道,一种数据模型必须包含三个基本的部分: 构造机制(数据结构):主要描述数据的类型.内容.性质以及数据间的联系等. 运算机制(数据操作):主要描述在相应的数据结构上的操作类型和操作方式. 约束机 ...

  5. jsp导出身份证到excel时候格式不正确

    今天早上客户跟我说excel导出身份证的时候显示有的对有的不对,我一看原来身份证以X结尾的能够,其他都显示不对.身份正显示如图所看到的: 在网上搜了一下发现,原来excel看你数字列超过12位就会显示 ...

  6. 实习生面试相关-b

    面试要准备什么 有一位小伙伴面试阿里被拒后,面试官给出了这样的评价:“……计算机基础,以及编程基础能力上都有所欠缺……”.但这种笼统的回答并非是我们希望的答案,所谓的基础到底指的是什么? 作为一名 i ...

  7. C#实现如何判断一个数组中是否有重复的元素 返回一个数组升序排列后的位置信息--C#程序举例 求生欲很强的数据库 别跟我谈EF抵抗并发,敢问你到底会不会用EntityFramework

    C#实现如何判断一个数组中是否有重复的元素   如何判断一个数组中是否有重复的元素 实现判断数组中是否包含有重复的元素方法 这里用C#代码给出实例 方法一:可以新建一个hashtable利用hasht ...

  8. 最新Bootstrap手册

    http://www.jqhtml.com/bootstraps-syntaxhigh/index.html

  9. [故障处理]西部数据wd elements xp 无法识别

    百度后,看到如下帖子,供需要的朋友参考,黑体字为本人修改添加: http://blog.sina.com.cn/s/blog_539747670102w62w.html 经咨询WD厂商(厂商电话800 ...

  10. HDU 5544 Ba Gua Zhen dfs+高斯消元

    Ba Gua Zhen Problem Description During the Three-Kingdom period, there was a general named Xun Lu wh ...