POJ2318TOYS(叉积判断点与直线位置)
题意:一个矩形被分成了n + 1块,然后给出m个点,求每个点会落在哪一块中,输出每块的点的个数
就是判断 点与直线的位置,点在直线的逆时针方向叉积 < 0,点在直线的顺时针方向叉积 > 0
// 可以选择二分查找
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long LL;
const int Max = + ;
int num[Max];
//int ux[Max], dx[Max];
struct Point
{
LL ux, dx;
};
LL Cross(LL x1, LL y1, LL x2, LL y2)
{
return x1 * y2 - y1 * x2;
}
int main()
{
int n, m, x1, x2, y1, y2;
while (scanf("%d", &n) != EOF && n)
{
scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
for(int i = ; i <= n; i++)
scanf("%d%d", &ux[i], &dx[i]);
ux[n + ] = x2; // 把最后边界也算进去
dx[n + ] = x2;
memset(num, , sizeof(num));
int x, y, l, r, mid;
for (int i = ; i <= m; i++)
{
scanf("%d%d", &x, &y);
if (!(x >= x1 && x <= x2 && y >= y2 && y <= y1)) // 不在矩形内
continue;
l = , r = n + ;
while (l < r)
{
mid = (l + r) / ;
if (Cross(x - dx[mid], y - y2, ux[mid] - dx[mid], y1 - y2) > ) // 如果 大于 0 说明 点在直线 右侧,所以改变左区间
l = mid + ;
else
r = mid; // r始终是满足条件的
}
num[r - ]++;
/*
for (int j = 1; j <= n + 1; j++)
{
if ( Cross(x - dx[j], y - y2, ux[j] - dx[j], y1 - y2) <= 0)
{
num[j - 1]++;
break;
}
}
*/
}
for (int i = ; i <= n; i++)
printf("%d: %d\n", i, num[i]);
printf("\n");
}
return ;
}
POJ2318TOYS(叉积判断点与直线位置)的更多相关文章
- POJ 2318 叉积判断点与直线位置
TOYS Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom ...
- POJ2318 TOYS(叉积判断点与直线的关系+二分)
Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...
- poj2318(叉积判断点在直线左右+二分)
题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- 判断两条直线的位置关系 POJ 1269 Intersecting Lines
两条直线可能有三种关系:1.共线 2.平行(不包括共线) 3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- POJ 1269 Intersecting Lines(判断两直线位置关系)
题目传送门:POJ 1269 Intersecting Lines Description We all know that a pair of distinct points on a plane ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
- POJ1269:Intersecting Lines(判断两条直线的关系)
题目:POJ1269 题意:给你两条直线的坐标,判断两条直线是否共线.平行.相交,若相交,求出交点. 思路:直线相交判断.如果相交求交点. 首先先判断是否共线,之后判断是否平行,如果都不是就直接求交点 ...
随机推荐
- sqlserver查询所有表名、字段名、类型、长度和存储过程、视图的创建语句
-- 获得存储过程创建语句 select o.xtype,o.name,cm.text from syscomments cm inner join sysobjects o on o.id=cm.i ...
- difference between append and appendTo
if you need append some string to element and need set some attribute on these string at the same ti ...
- SpringMVC学习--拦截器
简介 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 拦截器定义 定义拦截器,实现HandlerInterceptor接 ...
- bootstrap实现pc屏幕五等分
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...
- 【BZOJ 4456】【UOJ #184】【ZJOI 2016】旅行者
http://www.lydsy.com/JudgeOnline/problem.php?id=4456 http://uoj.ac/problem/184 参考(抄)的晨爷的题解(代码) 对矩形进行 ...
- Edge detection using LoG
intensity梯度值分布跟图片的大小有关, 比如将一张小图片放大后会变得很模糊, 原先清晰的edge, 即大的梯度值变得模糊. 但是原有的边缘通常还是肉眼可分辨的. 但用Sobel 算子可能就检测 ...
- poj2186 强连通缩点
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 29773 Accepted: 12080 De ...
- linux下截取整个网页
前提需要安装 gimp图片处理软件 打开gimp 文件-创建-从网页 然后输入网页地址就可以截取整个网页了
- Input checkbox 添加样式背景
<style type="text/css"> .chk_1 { width: 20px; height: 20px; position: absolute; top: ...
- Oauth2.0 用Spring-security-oauth2 来实现
前言: 要准备再次研究下 统一认证的功能了,我还是觉得实现统一认证 用Oauth2 最好了,所以,现在再次收集资料和记笔记. 正文: 一.概念理解 OAuth2, 是个授权协议, RFC文档见:htt ...