poj 2398 Toy Storage【二分+叉积】
二分点所在区域,叉积判断左右
#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【二分+叉积】的更多相关文章
- POJ 2398 Toy Storage 二分+叉积
Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- POJ 2398 Toy Storage(叉积+二分)
Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...
- poj 2398 Toy Storage(计算几何)
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3146 Accepted: 1798 Descr ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
随机推荐
- markdown八条基础语法
1.空行 答:使用全角打出空格,之后再换行就可以打出空行了 2.标题 答:#表示标题,#表示一级标题,字号最大,一共有六级标题 3.列表 答:- 无序列表,1. 有序列表,注意和文本之间有空格 4.链 ...
- LightOJ1094 - Farthest Nodes in a Tree(树的直径)
http://lightoj.com/volume_showproblem.php?problem=1094 Given a tree (a connected graph with no cycle ...
- Linux--进程组、会话、守护进程(转)
http://www.cnblogs.com/forstudy/archive/2012/04/03/2427683.html 进程组 一个或多个进程的集合 进程组ID: 正整数 两个函数 getpg ...
- Java实验——输出二维数组连续二维子数组的最大和
该算法思路,根据我博客里面一维子数组求和的思路,可以用一个新的二维数组对该二维区域的数组进行求和,例如新的二维数组的第5个位置,就代表从1到5斜对角线的块状区域的和,即1,2,4,5这4个数的和,x个 ...
- java基础 4 继承(1)访问权限与作用域
作用域与可见性 当前类 同一package 子类 其他package public √ √ √ √ protected √ √ √ defalut √ √ private √
- 我在使用eclipse配置Tomcat服务器的时候发现,默认情况下Tocmat把我们部署的项目放在了workspaces下面,而不是像Myeclipse默认的那样放在tomcat的安装路径下。
1.我在使用eclipse配置Tomcat服务器的时候发现,默认情况下Tocmat把我们部署的项目放在了workspaces下面,而不是像Myeclipse默认的那样放在tomcat的安装路径下. 2 ...
- 深信服:Weblogic集群负载均衡技术解决方案
深信服应用交付产品替换集群中的Master节点,以双机模式部署接入,为Cluster 内的服务器提供应用交换服务,结合健康检查和业务特点,提供十几种负载均衡算法组合,满足多种生产环境下的业务需求. ...
- 【网络】TCP协议
一.概述 主要特点: 1)面向连接的运输层协议 2)每一条TCP连接只能有两个端点,每一条TCP连接只能是点对点的(一对一) 3)TCP提供可靠交付的服务 4)TCP提供全双工通信 5)面向字节流:T ...
- ThoughtWorks技术雷达
ThoughtWorks技术雷达 技术成熟方案的一个推荐网站.
- grep命令使用技巧
grep如何实现全词查找例如:要查找name这个单词,反馈的查找结果不能包含namespace这样的模式,但是可以包含name()这样的模式,即要查找的单词两端不可以有其他的数字或者字母,但可以有空格 ...