2318

2398

题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里。

思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧),再因为是简单几何线段不相较,即有序分布,那么在求在哪个区间时可以先对所有线段根据x坐标排序,使用二分减少复杂度。

/** @Date    : 2017-07-11 11:05:59
* @FileName: POJ 2318 叉积性质.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; struct Point
{
int x, y;
Point(){}
Point(int xx, int yy){x = xx, y = yy;}
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 cross(Point a, Point b)
{
return a.x * b.y - a.y * b.x;
} struct Line
{
Point s, t;
Line(){}
Line(Point ss, Point tt){s = ss, t = tt;}
}; int JudegeCross(Point p0, Point p1, Point p2)
{
return cross(p1 - p0, p2 - p0);
} Line li[N];
int ans[N];
int vis[N];
int cmp(Line a, Line b)
{
return a.s.x < b.s.x;
} int main()
{
int n, m, x1, x2, y1, y2;
while(~scanf("%d", &n) && n)
{
MMF(ans);
MMF(vis);
scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
for(int i = 0; i < n; i++)
{
int s, t;
scanf("%d%d", &s, &t);
li[i] = Line(Point(s, y1), Point(t, y2));
}
li[n] = Line(Point(x2, y1), Point(x2, y2));
sort(li, li + n + 1, cmp);
while(m--)
{
int x, y;
scanf("%d%d", &x, &y);
Point p = Point(x, y);
int l = 0, r = n;
int pos = 0;
while(l <= r)
{
int mid = (l + r) >> 1;
if(JudegeCross(p, li[mid].s, li[mid].t) < 0)
{
pos = mid;
r = mid - 1;
}
else
l = mid + 1;
}
ans[pos]++;
}
printf("Box\n");
for(int i = 0; i <= n; i++)
if(ans[i])
vis[ans[i]]++;
for(int i = 1; i <= n; i++)
if(vis[i])
printf("%d: %d\n", i, vis[i]);
}
return 0;
}
/** @Date    : 2017-07-11 11:05:59
* @FileName: POJ 2318 叉积性质.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; struct Point
{
int x, y;
Point(){}
Point(int xx, int yy){x = xx, y = yy;}
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 cross(Point a, Point b)
{
return a.x * b.y - a.y * b.x;
} struct Line
{
Point s, t;
Line(){}
Line(Point ss, Point tt){s = ss, t = tt;}
}; int JudegeCross(Point p0, Point p1, Point p2)
{
return cross(p1 - p0, p2 - p0);
} Line li[N];
int ans[N]; int main()
{
int n, m, x1, x2, y1, y2;
while(~scanf("%d", &n) && n)
{
MMF(ans);
scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
for(int i = 0; i < n; i++)
{
int s, t;
scanf("%d%d", &s, &t);
li[i] = Line(Point(s, y1), Point(t, y2));
}
li[n] = Line(Point(x2, y1), Point(x2, y2));
while(m--)
{
int x, y;
scanf("%d%d", &x, &y);
Point p = Point(x, y);
int l = 0, r = n;
int pos = 0;
while(l <= r)
{
int mid = (l + r) >> 1;
if(JudegeCross(p, li[mid].s, li[mid].t) < 0)
{
pos = mid;
r = mid - 1;
}
else
l = mid + 1;
}
ans[pos]++;
}
for(int i = 0; i <= n; i++)
{
printf("%d: %d\n", i, ans[i]);
}
printf("\n");
}
return 0;
}

POJ 2318/2398 叉积性质的更多相关文章

  1. 二分+叉积判断方向 poj 2318 2398

    // 题意:问你每个区域有多少个点 // 思路:数据小可以直接暴力 // 也可以二分区间 #include <cstdio> #include <cstring> #inclu ...

  2. POJ 2318 TOYS 叉积

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

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

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

  4. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  5. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  6. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  7. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

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

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

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

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

随机推荐

  1. CS小分队第二阶段冲刺站立会议(5月28日)

    昨日成果:昨天对我们的软件的主界面进行了思考,考虑到许多人建议我们团队添加可以自主增加软件快捷键的功能,我对这一想法的可行性和项目总体策划进行评估分析后,决定正式实施:已经完成从电脑上添加文件在我们的 ...

  2. Java 将数字转为16进制,然后转为字符串类型 将空格去掉。终结版

    //十进制转为十六进制 public class ArrayTest7 { public static void main(String[] args){ System.out.println(toH ...

  3. 软工网络15团队作业4-DAY2

    每个人的工作 (有work item 的ID),并将其记录在码云项目管理中: 昨天已完成的工作. 张陈东芳:查看数据库的连接 吴敏烽:规范商品实体类 周汉麟:研究获取商品信息的方法 林振斌:研究获取商 ...

  4. tomcat下部署了多个项目启动报错java web error:Choose unique values for the 'webAppRootKey' context-param in your web.xml files

    应该是tomcat下部署了多个项目且都使用log4j. <!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root". ...

  5. git管理策略

    master:生产环境,用于发布正式稳定版 release-*.*:预发布分支,发布稳定版之前的正式分支 develop:开发分支,测试环境中使用 feature/who xxx:功能分支,功能未开发 ...

  6. 【开发工具IDE】eclipse的web项目的tomcat安装部署问题

    一.发现问题 在eclipse中新建Dynamic Web Project,配置好本地的tomcat并写好代码后选择Run on Server,但运行后发现在tomcat的安装目录下的webapps并 ...

  7. 洛谷 P3376 【模板】网络最大流

    题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点序号.汇点序号. 接下来M行每行 ...

  8. Probability|Given UVA - 11181(条件概率)

    题目大意:n个人去购物,要求只有r个人买东西.给你n个人每个人买东西的概率,然后要你求出这n个人中有r个人购物并且其中一个人是ni的概率pi. 类似于5个人中 抽出三个人  其中甲是这三个人中的一个的 ...

  9. 前端跨域问题相关知识详解(原生js和jquery两种方法实现jsonp跨域)

    1.同源策略 同源策略(Same origin policy),它是由Netscape提出的一个著名的安全策略.同源策略是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正 ...

  10. Omeed 线段树

    目录 题面 题解 代码 题面 2.12 - - - 题解 大概还是挺妙的? 首先基础分和连击分互不干扰,所以可以分开统计. 基础分的统计比较简单,等于: \[A \sum_{i = l}^{r} p_ ...