题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y)。现在要问第几个位置上有多少个玩具。

思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ^ p1p0) (记得不能搞反顺序,不同的),如果他们的叉积是小于0,那么就是在线段的左边,否则右边。所以,可以用二分找,如果在mid的左边,end=mid-1 否则begin=mid+1。结束的begin,就是第一条在点右边的线段

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = +;
struct coor
{
double x,y;
coor(){}
coor(double xx,double yy):x(xx),y(yy){}
double operator ^(coor rhs) const //计算叉积(向量积)
{
return x*rhs.y - y*rhs.x;
}
coor operator -(coor rhs) const //坐标相减,a-b得到向量ba
{
return coor(x-rhs.x,y-rhs.y);
}
double operator *(coor rhs) const //数量积
{
return x*rhs.x + y*rhs.y;
}
};
struct Line
{
coor point1,point2;
Line(){}
Line(coor xx,coor yy):point1(xx),point2(yy){}
}a[maxn];
int n,m;
double xx1,yy1,xx2,yy2;
int cnt[maxn];
int calc (coor t)
{
int begin=,end=n;
while(begin<=end)
{
int mid = (begin+end)/;
coor ff1 = a[mid].point2 - a[mid].point1; //point1是起点
coor ff2 = t - a[mid].point1;
if ((ff1^ff2) < )
{
end=mid-;
}
else begin=mid+;
}
return begin;
}
void work ()
{
memset(cnt,,sizeof cnt);
for (int i=;i<=n;++i)
{
double xxx1,xxx2;
scanf("%lf%lf",&xxx1,&xxx2);
a[i].point1.x=xxx1, a[i].point1.y=yy1;
a[i].point2.x=xxx2, a[i].point2.y=yy2;
}
for (int i=;i<=m;++i)
{
coor t;
scanf("%lf%lf",&t.x,&t.y);
cnt[calc(t)-]++;
//printf ("%d\n",calc(t));
}
for (int i=;i<=n;++i)
{
printf ("%d: %d\n",i,cnt[i]);
}
return ;
}
int main()
{
#ifdef local
freopen("data.txt","r",stdin);
#endif
//while(~scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y) && (a.x+a.y+b.x+b.y)) work();
while(scanf("%d%d%lf%lf%lf%lf",&n,&m,&xx1,&yy1,&xx2,&yy2)!=EOF && n)
{
work();
printf ("\n");
}
return ;
}

POJ 2318 TOYS 利用叉积判断点在线段的那一侧的更多相关文章

  1. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  2. poj 2318(叉积判断点在线段的哪一侧)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description ...

  3. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  4. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

  5. poj 2398(叉积判断点在线段的哪一侧)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5016   Accepted: 2978 Descr ...

  6. POJ 2318 TOYS (叉乘判断)

    <题目链接> 题目大意: 给出矩形4个点和n个挡板俩顶点的位置,这n个挡板将该矩形分成 n+1块区域,再给你m个点的坐标,然你输出每个区域内有几个点. 解题思路: 用叉乘即可简单判断点与直 ...

  7. POJ 2318 TOYS (计算几何,叉积判断)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

  8. POJ 2318 TOYS (叉积+二分)

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  9. POJ 2318 TOYS 叉积

    题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...

随机推荐

  1. bzoj 1257 余数之和 —— 数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 \( \sum\limits_{i=1}^{n}k\%i = \sum\limits_ ...

  2. Percona Xtrabackup 备份MySQL 实例(转)

    老规矩,开场白,刚开始用mysqldump,备份100G+的数据库,再加上服务器繁忙,备份速度像蜗牛似的,于是寻找更高效的备份方法.网上都说用xtrabackup比较适合备份大的数据库,而且备份效率也 ...

  3. C#中如何获取汉字的笔画数和汉字的拼音

    以前玩过一个游戏,输入两个人的名字然后点击缘分就能产生一段缘分测试的结果,后来经过分析知道是根据名字笔画数之差来弄的小游戏,于是就在百度上找怎么得到汉字的笔画数,也没找到自己想要的答案,问遍了所有的人 ...

  4. virtual judge(专题一 简单搜索 B)

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  5. 通过pip3安装ipython

    操作系统:Centos7.4:ipython可以用来测试python语句,故需要安装. 首先需要安装epelde的扩展库: easy_install是由PEAK(Python Enterprise A ...

  6. AxInterop.ShockwaveFlashObjects.dll 问题

    在实际项目中引用此dll加载项目启动动画(swf),但在64位上此dll并不支持,解决办法有待商讨,个人在项目中,把加载动画的部分给注释掉了,不给项目中签入,他们用的都是32位系统,我的是64位的.请 ...

  7. 【spring boot logback】日志颜色渲染,使用logback-spring.xml自定义的配置文件后,日志没有颜色了

    接着spring boot日志logback解析之后,发现使用logback-spring.xml自定义的配置文件后,日志没有颜色了 怎么办? 官网处理日志链接:https://logback.qos ...

  8. es6基础系列五--数组的拓展

    Array.from() 用于将两类对象转为真正的数组,类似数组对象和可遍历对象(包括数据结构Set和Map)转化为数组 格式:Array.from(arrayLike[, mapFn[, thisA ...

  9. linux添加软件的service start/stop快捷服务(简单版)

    首先我们先需要一款软件,例如“apache” 安装解压至相应目录“/home/aaa/apache” 开始操作:进入“/etc/init.d/”中,新建一个service服务运行脚本“tomcat”, ...

  10. If,for,range混合使用笔记-(VBA视频教程2:使用IF进行逻辑判断)

    -- 新建表格:#单元格a1-a100全部等于1的代码 Sub test() Dim i As Integer For i = To Range( Next End Sub -- 新建表格:#单元格a ...