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. go中&^(按位置零)符号的含义

    go中有一个 &^ 的运算符,它代表的是按位置零 首先来看下几个输出例子: i := 1 &^ 0 fmt.Println("1 &^ 0 -- ",i) ...

  2. C#中精确计时的一点收获 Stopwatch

    http://www.cnblogs.com/jintianhu/archive/2010/09/01/1815031.html 参考: https://www.cnblogs.com/kissdod ...

  3. MethodInvoker委托,跨线程访问

    Invoke(new MethodInvoker(delegate { textBox1.Enabled = true; })); 上面是简单缩写,也可以写成 private void btnOK_C ...

  4. linux学习 - 基本命令篇

    关机重启命令 基本操作之修改用户名(Ubuntu) 查看系统版本号 查看系统是32位还是64位 系统进程信息查看 查看某个端口被占用的情况 查看磁盘分区使用情况 df 命令 fdisk 关机重启命令 ...

  5. Visual C++ 2010 SP1 x86&x64

    Microsoft Visual C++ 2010 SP1 Redistributable Package (x86) https://www.microsoft.com/en-us/download ...

  6. 第四周(1):数据分布-Python实战

    数据准备 数据集地址:http://jse.amstat.org/datasets/normtemp.dat.txt 数据集描述:总共只有三列:体温.性别.心率 数据集详细描述:Journal of ...

  7. 使用JavaConfig配置SpringMVC

    目录结构 web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi ...

  8. IntelliJ Cannot find declaration to goto----解决方案

    系统中已经有了该类库,还是找不到类提示 close the project in intellij. close intellij. go to the project folder and dele ...

  9. Vue-使用计时器实现跑马灯效果

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 英语fieldyellowstone田黄石fieldyellowstone单词

    田黄石(Field yellow stone),简称“田黄”,产于福州市寿山乡“寿山溪”两旁之水稻田底下.呈黄色而得名.寿山石优良品种.狭义的田黄石指“田坑石”,广义的田黄石是指其化学成分相同的一类印 ...