zoj1041 Transmitters (叉积性质的应用)

叉积: (其值等于两向量组成的三角形的有向面积的两倍)

AXB = A.x * B.y - A.y * B.x

Vector Cross(Vector A, Vector B) { return(A.x  * B.y - A.y * B.x); }


性质:

AXB的符号判断(夹角小于180度)

AXB > 0 :则B在A的左边

AXB < 0 :则B在A的右边

AXB = 0 :则A和B共线,方向同向或反向

----------------------------------------------------------------------------------------------------

zju1041

问题描述:在有n个点的面上有一个给定了半径和圆心坐标的半圆,半圆可以绕圆心转动但不可以平移,求半圆最多能包含多少点,边界上的点认为在圆内。





#include <cstdio>
#include <cstring>
#include <cmath>
const int maxn =1000 + 5;
using namespace std;

struct Vector
{
    int x, y;
    Vector(int x=0, int y=0) : x(x), y(y) {}
} f[150];

Vector operator - (Vector A, Vector B){return Vector(A.x-B.x, A.y-B.y); }

int Cross(Vector A, Vector B) {return A.x*B.y - A.y*B.x; }


int main()
{
    int xx, yy;
    double r;
    Vector t;
    int n, i, k;
    while(~scanf("%d%d%lf",&t.x,&t.y,&r))
    {
        if(r < 0) break;
        scanf("%d",&k);
        n = 0;
        r = r * r;
        while(k--)
        {
            scanf("%d%d",&xx,&yy);
            if( (xx-t.x)*(xx-t.x)+(yy-t.y)*(yy-t.y)  <= r)
            {
                f[n].x = xx;
                f[n++].y = yy;
            }
        }
        int max  =  0;
        for(i=0; i<n; ++i)
        {
            int totl = 0, totr = 0, j;
            for(j=0; j<n; ++j)
            {
                int d = Cross(f[i]-t, f[j]-t);
                if(d == 0)
                {
                    totl++, totr++;
                }
                if(d > 0) totl++;
                if(d < 0) totr++;
            }
            if(totl > max) max = totl;
            if(totr > max) max = totr;
        }
        printf("%d\n",max);

    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值