poj 4048

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

struct point{
    double x,y;
}P;
struct line{
    point a,b;
}a[1510],L1,L2;

double xmult(point p1, point p2, point p0) {
    return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
int dot_online_in(point p, point l1, point l2) {
    return zero(xmult(p,l1,l2)) && (l1.x - p.x) * (l2.x - p.x) < eps
        && (l1.y - p.y) * (l2.y - p.y) < eps;
}
int same_side(point p1, point p2, line l) {
    return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) > eps;
}
int dots_inline(point p1, point p2, point p3) {
    return zero(xmult(p1,p2,p3));
}
int dot_online_in(point p, line l) {
    return zero(xmult(p,l.a,l.b)) && (l.a.x - p.x) * (l.b.x - p.x) < eps
        && (l.a.y - p.y) * (l.b.y - p.y) < eps;
}
int intersect_in(line u, line v) {
    if (!dots_inline(u.a, u.b, v.a) || !dots_inline(u.a, u.b, v.b))
        return !same_side(u.a, u.b, v) && !same_side(v.a, v.b, u);
    return dot_online_in(u.a, v) || dot_online_in(u.b, v)
        || dot_online_in(v.a, u) || dot_online_in(v.b, u);
}
int main()
{
    int T, n;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf%lf",&a[i].a.x,&a[i].a.y,&a[i].b.x,&a[i].b.y);
        scanf("%lf%lf",&P.x,&P.y);
        int ans=0;
        for(int i=0;i<n;i++)
        {
            int cnt1=0,cnt2=0;
            L1.a=P;L2.a=P;
            L1.b.x=20000*(a[i].a.x-P.x);
            L1.b.y=20000*(a[i].a.y-P.y);
            L2.b.x=20000*(a[i].b.x-P.x);
            L2.b.y=20000*(a[i].b.y-P.y);
            for(int j=0;j<n;j++)
            {
                if(intersect_in(L1,a[j]))
                    cnt1++;
                if(intersect_in(L2,a[j]))
                    cnt2++;
            }
            ans=max(max(cnt1,cnt2),ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}

转载于:https://www.cnblogs.com/nulle/archive/2012/09/19/2693759.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值