解题关键:计算几何入门题,通过叉积判断。

两个向量的关系:

P*Q>0,Q在P的逆时针方向;

P*Q<0,Q在P的顺时针方向;

P*Q==0,Q与P共线。

实际就是用右手定则判断的。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;
struct point{
int x,y;
};
int n,m,x1,x2,y11,y2;
struct Line{
point a,b;
}A[];
double operator*(point p1,point p2){return p1.x*p2.y-p2.x*p1.y;}
point operator-(point A,point B){return {A.x-B.x,A.y-B.y};}
int pos[];
bool judge(point t,int mid){//叉积
point tt=A[mid].b-A[mid].a;
int ans=tt*(t-A[mid].a);
return ans<=;
} int erfen(point xx){
int l=,r=n;
while(l<r){
int mid=(l+r)>>;
if(judge(xx,mid)) r=mid;
else l=mid+;
}
return r;
} int main(){
while(scanf("%d",&n)!=EOF&&n){
scanf("%d%d%d%d%d",&m,&x1,&y11,&x2,&y2);
for(int i=;i<n;i++){
int xd,xu;
scanf("%d%d",&xu,&xd);
A[i]={{xu,y11},{xd,y2}};
}
memset(pos,,sizeof pos);
for(int i=;i<m;i++){
int xx,yy;
scanf("%d%d",&xx,&yy);
point t={xx,yy};
int ans=erfen(t);
pos[ans]++;
}
for(int i=;i<=n;i++){
printf("%d: %d\n",i,pos[i]);
}
printf("\n");
}
return ;
}

[poj2318]TOYS(直线与点的位置关系)的更多相关文章

  1. POJ_2318_TOYS&&POJ_2398_Toy Storage_二分+判断直线和点的位置关系

    POJ_2318_TOYS&&POJ_2398_Toy Storage_二分+判断直线和点的位置 Description Calculate the number of toys th ...

  2. Segments---poj3304(判断直线与线段的位置关系)

    题目链接:http://poj.org/problem?id=3304 题意:给你n个线段,求是否有一条直线与所有的线段都相交,有Yes,没有No; 枚举所有的顶点作为直线的两点,然后判断这条直线是否 ...

  3. TOYS(计算几何基础+点与直线的位置关系)

    题目链接:http://poj.org/problem?id=2318 题面: TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submiss ...

  4. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  5. Intersecting Lines---poj1269(求两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题意:给你两条直线上的任意不同的两点,然后求两条直线的位置关系,如果相交于一点输出该点坐标; #include<iostr ...

  6. 判断两条直线的位置关系 POJ 1269 Intersecting Lines

    两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, ...

  7. Intersecting Lines (计算几何基础+判断两直线的位置关系)

    题目链接:http://poj.org/problem?id=1269 题面: Description We all know that a pair of distinct points on a ...

  8. poj 1269 判断直线的位置关系

    题目链接 题意 判断两条直线的位置关系,重合/平行/相交(求交点). 直线以其上两点的形式给出(点坐标为整点). 思路 写出直线的一般式方程(用\(gcd\)化为最简), 计算\(\begin{vma ...

  9. POJ-2318 TOYS 计算几何 判断点在线段的位置

    题目链接:https://cn.vjudge.net/problem/POJ-2318 题意 在一个矩形内,给出n-1条线段,把矩形分成n快四边形 问某些点在那个四边形内 思路 二分+判断点与位置关系 ...

随机推荐

  1. C++(十三)— map的排序

    在c++中有两个关联容器,第一种是map,内部是按照key排序的,第二种是unordered_map,容器内部是无序的,使用hash组织内容的. 1.对有序map中的key排序 如果在有序的map中, ...

  2. ural 2020 Traffic Jam in Flower Town(模拟)

    2020. Traffic Jam in Flower Town Time limit: 1.0 secondMemory limit: 64 MB Having returned from Sun ...

  3. 51nod 1672 贪心/队列

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1672 1672 区间交 基准时间限制:1 秒 空间限制:131072 K ...

  4. New Concept English three (57)

    28w/m 54errors I stopped to let the car cool off and to study the map. I had expected to be near my ...

  5. 学习汤姆大叔《深入理解JavaScript系列》有感(1) —— 立即调用的函数表达式

    一. 下面代码用于理解函数的声明和调用. function makeCounter() { // 只能在makeCounter内部访问i var i = 0; return function () { ...

  6. codeforces C. Pearls in a Row map的应用

    C. Pearls in a Row time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. burpsuite使用以及repeater模块实现重放攻击

    第一.burp suit是什么? Burp Suite 包含了一系列burp 工具,这些工具之间有大量接口可以互相通信,之所以这样设计的目的是为了促进和提高 整个攻击的效率.平台中所有工具共享同一ro ...

  8. Bender Problem

    Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n ...

  9. RabbitMQ集群 Docker一键部署

    以下内容来自网络转载 步骤1. 安装docker 以centos7为例,https://docs.docker.com/engine/installation/linux/centos/ 步骤2. 创 ...

  10. ubuntu 挂载exfat

    在ubuntu下,由于版权的原因,默认不支持exfat格式的u盘,不过可以很方便就能添加对exfat的支持: 1.对于ubuntu 14.04版本,直接运行下面的命令就可以了: sudo apt-ge ...