POJ 2318 TOYS 计算几何 判断点在线段的哪一侧



#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
#include <algorithm>
#include <functional>
#include <vector>
#include <iomanip>
#include <cmath>
#include <iostream>
#include <sstream>
#include <stack>
#include <set>
#include <bitset>
using namespace std;

const int MAX = 5050;

struct Vector
{
    int x, y;
    Vector() = default;
    Vector(int xx, int yy) : x(xx), y(yy) {}
    Vector operator-(const Vector &a) const
    {
        return Vector(x - a.x, y - a.y);
    }
    int operator^(const Vector &a) const
    {
        return x * a.y - y * a.x;
    }
};

typedef Vector Point;

struct Segment
{
    Point s, e;
    Segment() = default;
    Segment(Point ss, Point ee) : s(ss), e(ee) {}
};

int CrossProduct(const Point &p0, const Point &p1, const Point &p2)
{
    return (p1 - p0) ^ (p2 - p0);
}

Segment Ss[MAX];
int Ans[MAX];

int main()
{
    cin.sync_with_stdio(false);
    int n, m, x1, y1, x2, y2, a, b;
    while (cin >> n && n)
    {
        memset(Ans, 0, sizeof(Ans));
        cin >> m >> x1 >> y1 >> x2 >> y2;
        for (int i = 0; i < n; i++)
        {
            cin >> a >> b;
            Ss[i] = Segment(Point(a, y1), Point(b, y2));
        }
        for (int i = 0; i < m; i++)
        {
            cin >> a >> b;
            Point temp(a, b);
            int l = 0, r = n - 1, mid;
            while (l < r)
            {
                mid = (l + r) >> 1;
                if (CrossProduct(temp, Ss[mid].s, Ss[mid].e) > 0)
                    l = mid + 1;
                else
                    r = mid;
            }
            if (CrossProduct(temp, Ss[l].s, Ss[l].e) < 0)
                Ans[l]++;
            else
                Ans[l + 1]++;
        }
        for (int i = 0; i <= n; i++)
            cout << i << ": " << Ans[i] << '\n';
        cout << '\n';
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值