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 ...
随机推荐
- js正则匹配身份证号 有坑
// 不能加g,每次匹配会以lastIndex为起始位去查找 // 若加g,匹配到会用最后一位的index去改变lastIndex,没有匹配到则会把lastIndex重置为0 // 不加g,lastI ...
- Search in Rotated Sorted Array(二分查找)
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- 【TFS 2017 CI/CD系列 - 03】-- Release篇
为Project创建Release必须要先创建Build,若还没有Build definition请看上一篇文章:[TFS 2017 CI/CD系列 - 02]-- Build篇 一.创建Releas ...
- sys.argv的妙用:python命令行参数列表的修改、增加、删除
是否妙用取决于你怎么用 1.sys.argv是用来获取命令行参数的方法,本身是一个list.你搜其实用方法,这方面的介绍最多,这里不赘述 2.那么问题是:sys.argv可以赋值吗?可以扩充吗?可以修 ...
- crontab使用简介
crontab的配置文件: 前四行是用来配置crond任务运行的环境变量 第一行SHELL变量指定了系统要使用哪个shell,这里是bash 第二行PATH变量指定了系统执行命令的路径 第三行MAIL ...
- 去掉小程序textarea上的完成按钮栏
小程序textarea上会自动多一个完成按钮,如下图所示,如果是mpVue,在textarea添加 :show-confirm-bar="false" 即可.
- VS2015 android 设计器不能可视化问题解决。
近期安装了VS2015,体验了一下android 的开发,按模板创建执行了个,试下效果非常不错.也能够可视化设计.但昨天再次打开或创建一个android程序后,设计界面直接不能显示,显示错误:(可能是 ...
- VC++中的int main(int argc, char argv[])是什么意思
这是C/C++的一重要函数,叫主函数.无论程序多复杂,代码中必须有这么一个函数,也只能有一个这样的函数:程序执行时就是从这个函数进入的.由于问得比较笼统,如果你想知道详细情况的话,发给你一个网友的求助 ...
- js性能优化之函数节流(分流函数)
函数节流的原理 比如我们在window.onresize事件中要打印当前浏览器窗口的大小,在我们通过拖拽来改变窗口大小时候,打印窗口大小这个工作1s就运行了10次.而实际上我们只需要2次或者3次. 比 ...
- [原创+分享]Mandelbrot Explorer
Mandelbrot Explorer 是一款用于在MandelBort集/Julia集上进行无限漫游的软件,使用VS2013+CUDA6.5开发而成.它也是我学习CUDA开发的一个小小的成果,欢迎大 ...