poj2398 Toy Storage

链接

poj

题目大意

这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2。n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区域,然后分别用0到n表示,m代表玩具的个数,(x1,y1)代表盒子的左上顶点坐标,(x2,y2)代表盒子的右下顶点坐标,接下来的n行,每行都有两个数a,b,(a,y1),(b,y2)分别代表卡片的两个顶点位置,接下来的m行每行两个数从c,d,(c,d),代表玩具放置的坐标,最后让你输出当区域内玩具的个数(递增,0除外),以及有几个同样数目玩具的区域,当输入第一个数为0时结束。

思路

先把隔板排序。

然后每个玩具二分位置。用叉积判断。

代码

#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int N=1005;
const double eps=1e-10;
struct point {
double x,y;
}a[N],b[N];
point operator - (point a,point b) {
return (point){a.x-b.x,a.y-b.y};
}
double operator * (point a,point b) {
return a.x*b.y-b.x*a.y;
}
struct line {
double u,l;
}l[N];
int n,m;
bool cmp(line a,line b) {
return a.u<b.u;
}
int cnt[N],ans[N]; int main() {
while(scanf("%d",&n)!=EOF&&n) {
scanf("%d",&m);
scanf("%lf%lf%lf%lf",&b[0].x,&b[0].y,&a[n+1].x,&a[n+1].y);
a[0].x=b[0].x,a[0].y=b[n+1].y;
b[n+1].x=a[n+1].x,b[n+1].y=b[0].y;
for(int i=1;i<=n;++i)
scanf("%lf%lf",&l[i].u,&l[i].l);
sort(l+1,l+1+n,cmp);
for(int i=1;i<=n;++i) {
a[i].x=l[i].l,a[i].y=a[n+1].y;
b[i].x=l[i].u,b[i].y=b[0].y;
}
memset(cnt,0,sizeof(cnt));
memset(ans,0,sizeof(ans));
for(int i=1;i<=m;++i) {
point c;
scanf("%lf%lf",&c.x,&c.y);
if(!(a[n+1].y<=c.y&&c.y<=b[0].y&&b[0].x<=c.x&&c.x<=a[n+1].x)) continue;
int l=0,r=n+1;
while(l+1!=r) {
int mid=(l+r)>>1;
if((b[mid]-a[mid])*(c-a[mid])>0) r=mid;
else l=mid;
}
cnt[l+1]++;
}
puts("Box");
for(int i=1;i<=n+1;++i)
if(cnt[i]) ans[cnt[i]]++;
for(int i=1;i<=m;++i)
if(ans[i]) printf("%d: %d\n",i,ans[i]);
}
return 0;
}

poj2398 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(计算几何)

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

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

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

  4. poj 2398 Toy Storage(计算几何 点线关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4588   Accepted: 2718 Descr ...

  5. [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)

    题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...

  6. POJ 2398 Toy Storage(计算几何)

    题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 题解:通过斜率判断一个点是否在两条线段之间. /** 通过斜率比较点是否在两线段之 ...

  7. [poj2398]Toy Storage

    接替关键:和上题类似,输出不同,注意输入这道题需要排序. #include<cstdio> #include<cstring> #include<algorithm> ...

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

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

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

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

随机推荐

  1. c# .netcore oracle连接工具类

    1.先右键->添加NeGet包->引入Oracle.ManagedDataAccess.dll 2.将该类加入项目中 工具类: using System; using System.Col ...

  2. MySQL--用户管理 pymysql 索引

    目录 用户管理 创建mysql账户 权限管理 涉及到的表 pymysql 索引 语法 结论 用户管理 主要是为了控制权限,让不同的人只能操作只属于只记得那部分数据 创建mysql账户 账户中涉及三个数 ...

  3. js设置全局变量与读取全局变量

    方法1: 设置: var a = 1; 读取: a window.a window['a'] 方法2: 设置: window.b=2; 读取: b window.b window['b'] 方法3: ...

  4. Beego 学习笔记9:Boostrap使用介绍

    BootStrap布局 1>     下载地址: http://v3.bootcss.com/getting-started/#download 根据自己的需要,下载不同的版本.我这里使用的是1 ...

  5. Object中defineProperty数据描述

    Object.defineProperty是对对象中的属性进行数据描述的 使用语法: Object.defineProperty(obj,prop,descriptor) 使用示例: var data ...

  6. 40、js技巧(持续更新。。。)

    1.深拷贝对象: const a={name:'aaa',age:11} const b=JSON.parse(JSON.stringify(a)) 2.获取数组极值: let list = [1, ...

  7. HTML 图像标签(img)

    一.标签属性 属性就是一个实体的特性,例如:手机的属性有大小,颜色等,HTML标签也有自己的属性. 使用HTML制作网页时,如果想让HTML标签提供更多的信息,可以使用HTML标签的属性加以设置. 语 ...

  8. mysql字符串截取函数和日期函数

    注:mysql下标索引从1开始,并包含开始索引 1.left(str,len) index<=0,返回空 index>0,截取最左边len个字符 select ), ), ), )  结果 ...

  9. 云服务器 - 定时备份MariaDB/MySQL

    数据库数据备份尤为重要,而我们不会人工手动去备份,这样会很麻烦,我们都是通过服务器每日自定运行来做的,设置一个定时时间即可 首先我们看一下mysqldump这个文件的位置: 可以看到目录在 /usr/ ...

  10. IDisposable 接口

    提供一种用于释放非托管资源的机制. 地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.idisposable?view=netframewor ...