计算几何基础

唉,高中数学都忘干净了、

 叉积都不知道了

点积、叉积:传送门

关于两个求反正切函数的比较:传送门

比较:黑猫

关于极角排序:黑猫

POJ 2318

这题利用叉积判断点在线段的左侧还是右侧

叉积 < 0 左侧

叉积 > 0 右侧

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
//const int qq = 2e5 + 10;
const int INF = 1e9 + 10;
struct Point {
	int x, y;
	Point(){}
	Point(int _x, int _y) {
		x = _x, y = _y;
	}
	Point operator - (const Point &A) const {
		return Point(x - A.x, y - A.y);
	}
	int operator * (const Point &A) const {
		return x * A.x + y * A.y;
	}
	int operator ^ (const Point &A) const {
		return x * A.y - y * A.x;
	}
};
struct Line {
	Point s, e;
	Line(){}
	Line(Point _s, Point _e) {
		s = _s, e = _e;
	}
};
int xmult(Point p0, Point p1, Point p2) {
	return (p1 - p0) ^ (p2 - p0);
}
const int qq = 5050;
Line line[qq];
int ans[qq];

int main(){
	int n, m, x1, y1, x2, y2;
	bool first = true;
	while(scanf("%d", &n) != EOF) {
		if(!n)	break;
		if(first)	first = false;
		else	puts("");
		scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
		int Ui, Li;
		for(int i = 0; i < n; ++i) {
			scanf("%d%d", &Ui, &Li);
			line[i] = Line(Point(Ui, y1), Point(Li, y2));
		}
		line[n] = Line(Point(x2, y1), Point(x2, y2));
		int x, y;
		Point p;
		mst(ans, 0);
		while(m--) {
			scanf("%d%d", &x, &y);
			p = Point(x, y);
			int l = 0, r = n;
			int tmp;
			while(l <= r) {
				int mid = (l + r) >> 1;
				if(xmult(p, line[mid].s, line[mid].e) < 0) {
					tmp = mid;
					r = mid - 1;
				} else {
					l = mid + 1;
				}
			}
			ans[tmp]++;
		}
		for(int i = 0; i <= n; ++i) {
			printf("%d: %d\n", i, ans[i]);
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值