寒假笔记1

1.容斥定理:S(A,B,C)=S(A)+S(B)+S(C)+S(A,B,C)-S(A&&B)-S(B&&C)-S(C&&A)

计算几个集合的并集有多少个元素等。

2.点乘、叉乘:

点乘:向量a·向量b=x1*x2+y1*y2=一个实数。

叉乘:向量aX向量b=x1*y2-x2*y1=一个向量。

叉乘应用:判断一个向量在另一个向量的顺逆方向:

   aXb>0:a在b顺时针方向;

 aXb<0:a在b逆时针方向;

  aXb=0:a在b一条直线但无法判断同向逆向;

3.凸包

求凸包的四种方法:暴力枚举(O(n3))、分制(找最长直径分割)、步进(O(nh))、gramham()

列举gramham算法示例:

#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
#define eps 1e-8
#define PI 3.1415926535898
#define MAX 1000
struct node
{
    double x,y;
    node() {}
    node(double xx,double yy)
    {
        x=xx;
        y=yy;
    }
    node operator +(const node &b)const
    {
        return node(x+b.x,y+b.y);
    }
    node operator -(const node &b)const
    {
        return node(x-b.x,y-b.y);
    }
    double operator *(const node &b)const
    {
        return x*b.x+y*b.y;
    }
    double operator ^(const node &b)const
    {
        return x*b.y-y*b.x;
    }
};
double dis(node a,node b)
{
    return sqrt((a-b)*(a-b));
}
int sgn(double a)
{
    if(abs(a)<eps)return 0;
    if(a<0)return -1;
    return 1;
}
node node_set[MAX];
int ans[MAX],top;
bool cmp(node p1,node p2)
{
    double tmp=(p1-node_set[0])^(p2-node_set[0]);
    if(sgn(tmp)>0) return true;
    else if(sgn(tmp)==0&&dis(node_set[0],p1)<dis(node_set[0],p2)) return true;
    else return false;
}
void init(int n)
{
    int k;
    node p0;
    cin>>node_set[0].x>>node_set[0].y;
    p0.x=node_set[0].x;
    p0.y=node_set[0].y;
    k=0;
    for(int i=1; i<n; i++)
    {
        cin>>node_set[i].x>>node_set[i].y;
        if((p0.y>node_set[i].y)||((p0.y==node_set[i].y)&&(p0.x>node_set[i].x)))
        {
            p0.x=node_set[i].x;
            p0.y=node_set[i].y;
            k=i;
        }
    }
    node_set[k]=node_set[0];
    node_set[0]=p0;
    sort(node_set+1,node_set+n,cmp);
}
void graham(int n)
{
    if(n==1)
    {
        top=0;
        ans[0]=0;
    }
    if(n==2)
    {
        top=1;
        ans[0]=0;
        ans[1]=1;
    }
    if(n>2)
    {
        ans[0]=0;
        ans[1]=1;
        top=1;
        for(int i=2; i<n; i++)
        {
            while(top>0&&((node_set[ans[top]]-node_set[ans[top-1]])^(node_set[i]-node_set[ans[top-1]]))<=0) top--;
            top++;
            ans[top]=i;
        }
    }
}

4.皮克公式:S=n+s/2-1 求方格纸上的图形内包括多少个点n、多边形的面积S、边过的点s.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值