BZOJ 2618 [Cqoi2006]凸多边形

本文介绍了BZOJ 2618题目,涉及半平面交问题的解决方法。作者分享了原始的解题思路,并在2017年进行了复习,更新了注释以包含新的理解。
摘要由CSDN通过智能技术生成

半平面交

裸的,注意事项在代码里。

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define N 505
using namespace std;
namespace runzhe2000
{
    typedef double db;
    const db eps = 1e-5;
    struct point
    {
        db x, y;
        point operator + (const point &that) const {
  return (point){
  x + that.x, y + that.y};}
        point operator - (const point &that) const {
  return (point){
  x - that.x, y - that.y};}
        db operator * (const point &that) const {
  return x*that.y-y*that.x;}
        point operator * (const db &v) const {
  return (point){
  x*v, y*v};}
    }p[N];
    struct line
    {
        point p, v; db alpha;
        bool operator < (const line &that) const {
  return alpha < that.alpha;}
    }l[N], q[N];
    int n, lcnt, head, tail;
    point get_cp(line l1, line l2)
    {
        /*
            精妙的实现。考虑通过面积比得到高的比,再得到线段的比。注意叉乘别反了。 
        */ 
        point u = l1.p - l2.p; db base = (l2.v * u) / (l1.v * l2.v);
        return l1.p + l1.v * base;
    }
    bool onlef(point p, line l)
    {
        point u = p-l.p; return l.v * u > 0;
    }
    void HP()
    {
        sort(l+1, l+1+lcnt); 
        for(int i = 1; i <= lcnt; i++)
        {
            for(; tail - head >= 2 && !onlef(get_cp(q[tail-1], q[tail-2]), l[i]); tail--);
            if(tail - head >= 1 && fabs(l[i].alpha - 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值