• POJ 2318 TOYS/POJ 2398 Toy Storage


    计算几何终于开坑了。。。

    叉积+二分。

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #define maxn 5050
    using namespace std;
    struct point
    {
        int x,y;
        point (int x,int y):x(x),y(y) {}
        point () {}
        friend point operator-(point x,point y)
        {
            return point(x.x-y.x,x.y-y.y);
        }
    }p[maxn];
    struct line
    {
        point x,dt;
        line (point x,point dt):x(x),dt(dt) {}
        line () {}
        friend int operator*(line x,line y)
        {    
            return x.dt.x*y.dt.y-y.dt.x*x.dt.y;
        }     
    }l[maxn];
    int n,m,cnt[maxn],x1,y1,x2,y2,x,y;
    bool check(int xs) {return (line(l[xs].x,point(x,y)-l[xs].x)*l[xs])>=0;}
    int ask()
    {
        int l=0,r=n,ans=-1;
        while (l<=r)
        {
            int mid=(l+r)>>1;
            if (check(mid)) {ans=mid;l=mid+1;}
            else r=mid-1;
        }
        return ans;
    }
    int main()
    {
        for (;;)
        {
            scanf("%d",&n);if (!n) break;scanf("%d",&m);
            scanf("%d%d%d%d",&x1,&y2,&x2,&y1);
            memset(cnt,0,sizeof(cnt));
            l[0]=line(point(x1,y1),point(0,y2-y1));
            for (int i=1;i<=n;i++)
            {
                scanf("%d%d",&x,&y);
                l[i]=line(point(y,y1),point(x-y,y2-y1));    
            }
            l[n+1]=line(point(x2,y1),point(0,y2-y1));
            for (int i=1;i<=m;i++)
            {
                scanf("%d%d",&x,&y);
                cnt[ask()]++;
            }
            for (int i=0;i<=n;i++) printf("%d: %d
    ",i,cnt[i]);
            printf("
    ");
        }
        return 0;
    }
  • 相关阅读:
    第十一周课堂测试 -- 四则运算
    软件工程第十一周学习进度
    软件工程课堂测试2
    软件工程概论_课堂测试
    11.16 动手动脑
    动手动脑
    网络模型分析
    Actor模型原理
    linux下启动oracle
    Linux 环境下Oracle11g安装图文详细教程
  • 原文地址:https://www.cnblogs.com/ziliuziliu/p/6267121.html
Copyright © 2020-2023  润新知