POJ 2398

这道题目和上一道真是姐妹题目啊!就是多了一个排序,因为2318这题已经排好序了,而这题是没有排好序的!
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1005;
int num[maxn];
int n,m;


struct point
{
    double x;
    double y;
};


struct line
{
    point high,low;
}L[maxn];


bool cmp(const line &m1,const line &m2)
{
    if(m1.high.x==m2.high.x)
        return m1.low.x<m2.low.x;
    else
        return m1.high.x<m2.high.x;
}


double pp(const point &aa,const point &bb,const point &cc)
{
    return (cc.x-bb.x)*(aa.y-bb.y)-(cc.y-bb.y)*(aa.x-bb.x);
}




int solve(point &cc)
{
    int l=0;
    int r=n;
    while(l<r)
    {
        int mid=(l+r)>>1;
        if(pp(L[mid].high, L[mid].low, cc)>0)
        {
            l=mid+1;
        }
        else
        {
            r=mid;
        }
    }
    return l;
}




int main()
{
    int i;
    #ifndef ONLINE_JUDGE


        freopen("in.txt","r",stdin);


    #endif // ONLINE_JUDGE


    while(scanf("%d",&n),n)
    {
        double a_x,a_y,b_x,b_y;
        scanf("%d%lf%lf%lf%lf",&m,&a_x,&a_y,&b_x,&b_y);
        for(i=0; i<n; i++)
        {
            scanf("%lf%lf",&L[i].high.x,&L[i].low.x);
            L[i].high.y=a_y;
            L[i].low.y=b_y;
        }
        L[n].high.x=b_x;L[n].high.y=a_y;
        L[n].low.x=b_x;L[n].low.y=b_y;
        sort(L,L+n+1,cmp);
        point temp;
        memset(num,0,sizeof(num));
        for(i=0; i<m; i++)
        {
            scanf("%lf%lf",&temp.x,&temp.y);
            int k;
            k=solve(temp);
            num[k]++;
        }
        sort(num,num+n+1);
        int sum;
        int z=0;
        printf("Box\n");
        for(i=0; i<=n; i++)
        {
            if(num[i]>z)
            {
                if(z!=0)
                {
                    printf("%d\n",sum);
                }
                sum=1;
                z=num[i];
                printf("%d: ",z);
            }
            else
            sum++;
        }
        if(z!=0)
            printf("%d\n",sum);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值