POJ 2398 Toy Storage(叉积+二分)
Description
Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top:

We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.
Input
A line consisting of a single 0 terminates the input.
Output
Sample Input
4 10 0 10 100 0
20 20
80 80
60 60
40 40
5 10
15 10
95 10
25 10
65 10
75 10
35 10
45 10
55 10
85 10
5 6 0 10 60 0
4 3
15 30
3 1
6 8
10 10
2 1
2 8
1 5
5 5
40 10
7 9
0
Sample Output
Box
2: 5
Box
1: 4
2: 1
题意:与poj2318一样 统计每个隔断形成的区域内物品的数量
思路:叉积+二分 比poj2318多排序和统计的步骤
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,m,x,y,xx,yy,tx,ty,U,L;
int ans[maxn],num[maxn]; struct Point{
int x,y;
Point(){}
Point(int _x,int _y){
x=_x,y=_y;
}
Point operator + (const Point &b) const {
return Point(x+b.x,y+b.y);
}
Point operator - (const Point &b) const {
return Point(x-b.x,y-b.y);
}
int operator * (const Point &b) const {
return x*b.x+y*b.y;
}
int operator ^ (const Point &b) const {
return x*b.y-y*b.x;
}
}; struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){
s=_s,e=_e;
}
}line[maxn]; int xmult(Point p0,Point p1,Point p2){
return (p1-p0)^(p2-p0);
} bool cmp(Line a,Line b){
return a.s.x<b.s.x;
} int main(){
while(scanf("%d",&n)== && n){
scanf("%d%d%d%d%d",&m,&x,&y,&xx,&yy);
for(int i=;i<n;i++){
scanf("%d%d",&U,&L);
line[i]=Line(Point(U,y),Point(L,yy));
}
line[n]=Line(Point(xx,y),Point(xx,yy));
sort(line,line+n+,cmp);
Point p;
memset(ans,,sizeof(ans));
memset(num,,sizeof(num));
while(m--){
scanf("%d%d",&tx,&ty);
p=Point(tx,ty);
int l=,r=n;
int tmp;
while(l<=r){
int mid=(l+r)>>;
if(xmult(p,line[mid].s,line[mid].e)<){
tmp=mid;
r=mid-;
}
else l=mid+;
}
ans[tmp]++;
}
for(int i=;i<=n;i++){
if(ans[i]>) num[ans[i]]++;
}
printf("Box\n");
for(int i=;i<=n;i++){
if(num[i]>) printf("%d: %d\n",i,num[i]);
}
}
return ;
}
POJ 2398 Toy Storage(叉积+二分)的更多相关文章
- 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【二分+叉积】
二分点所在区域,叉积判断左右 #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- 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 ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- 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 ...
随机推荐
- Busybox的syslogd认识与使用
关键词:rcS.start-stop-daemon.syslogd.syslog().klogd.klogctl().syslog.conf./dev/log.facility/level等等. sy ...
- 静态代理与JDK动态代理
demo地址: https://github.com/ZbLeaning/leaning 代理: 为其他对象提供一种代理以控制对这个对象的访问.分为静态代理和动态代理.代理模式的目的就是为真实业务对象 ...
- IS创新之路 -- 都昌公司赋能型HIT企业发展之路
◆◆前言 近日,上海瑞金医院对我司表示:“我院从2000年开始自主开发医院信息系统,走出了一条可持续的信息化发展之路.已建成五大系统,284个子系统.但我院仍然坚持在努力推进以电子病历为核心医院信息化 ...
- PHP(SentCMS)网站 “新手”捉虫记
我拖着疲惫的身躯,努力打开眼皮在写...... 昨晚弄到12点,我感觉应该弄好了. 故事开头是这样的:我呢朋友有个网站需要开发,我当时没时间就包给外面的公司了,由于外面公司维护费用比较贵. 那么网站维 ...
- 老铁啊,我同你讲, 这年头不会点 Git 真不行!!!
-------------------------------------知识是一点一点的积累的, 也是一点一点的吸收的,没有人一口就能吃成一个胖子. 版本控制 说到版本控制,脑海里总会浮现大学毕业是 ...
- Day7 Numerical simulation of optical wave propagation之通过随机介质(如大气湍流)的传播(三)
三 执行湍流仿真 基本参数设置: 光场条件:波长wvl,源平面的光场U 传播几何结构:观察面孔径尺寸D2,传播距离Dz 湍流条件:大气折射率结构常数Cn2 1. 准备工作 确定传播几何结构 (程序: ...
- Linux下用户和raid练习题
1. 公司一开发人员申请对服务器10天的oldboy普通用户权限,如何操作? useradd oldboy passwd oldboy usermod -e `date -d "10day& ...
- CentOS 7 rpm -i 时 警告warning: /var/tmp/rpm-tmp.z7O820: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY 解决方法
这是由于yum安装了旧版本的GPG keys造成的,解决办法就是 运行下面命令即可 # rpm --import /etc/pki/rpm-gpg/RPM* 查询已安装的rpm源 # rpm -qa ...
- 一招明白URL和URI的区别
URL和URI的区别(示例): URL[统一资源定位器]: http://localhost:8080/api/account/queryAccountInfo URI[统一资源定位符]: /api/ ...
- Sqoop export(Hive to MySQL) 的一些 reference
之后可能会整理成文章..还有一些坑没趟完. Reference: https://cloud.tencent.com/developer/article/1078473 Sqoop抽取Hive Pa ...