zoukankan      html  css  js  c++  java
  • Toy Storage

    Toy Storage

    题型与2318 TOYS一样,注意要对线段排序,现在模板又更新了~~

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string.h>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<vector>
    #include<cmath>
    #include<stdlib.h>
    #include<time.h>
    using namespace std;
    #define MS0(a) memset(a,0,sizeof(a))
    const int MAXN = 1050;
    struct point{
        int x,y;
        point(){}
        point(int _x,int _y){
            x = _x; y = _y;
        }
        long long operator *(const point &b)const{// 点向量叉乘
            return (1LL*x*b.y - 1LL*y*b.x);
        }
        point operator -(const point &b)const{
            return point(x - b.x,y - b.y);
        }
        long long dot(const point &b){    //点乘
            return 1LL*x*b.x + 1LL*y*b.y;
        }
        double dist(const point &b){
            return sqrt(1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y));
        }
        long long dist2(const point &b){
            return 1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y);
        }
        double len(){
            return sqrt(1LL*x*x+1LL*y*y);
        }
        double point_to_segment(point b,point c)//点a到“线段” bc的距离
        {
            point v[4];
            v[1] = {c.x - b.x,c.y - b.y};
            v[2] = {x - b.x,y - b.y};
            v[3] = {x - c.x,y - c.y};
            if(v[1].dot(v[2]) < 0) return v[2].len();
            if(v[1].dot(v[3]) > 0) return v[3].len();
            return fabs(1.*(v[1]*v[2])/v[1].len());
        }
        long long Xmult(point b,point c){   // 当a->b与a->c顺时针转时,返回正;
            return (b-*this)*(c-*this);
        }
        bool operator <(const point &b)const{
            return y < b.y||(y == b.y && x < b.x);
        }
        void input(){
            scanf("%d%d",&x,&y);
        }
    }p[MAXN];
    
    struct Line{
        point s,t;
        Line(){}
        Line(point _s,point _t){
            s = _s,t =_t;
        }
        bool operator <(const Line &b)const{
            return s < b.s;
        }
    }line[MAXN];
    
    int ans[MAXN],ret[MAXN];
    int main()
    {
        int n,m,i,j,x1,y1,x2,y2,kase = 0,U,L;
        while(scanf("%d",&n),n){
            MS0(ans);
            MS0(ret);
            scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
            for(i = 1;i <= n;i++){
                scanf("%d%d",&U,&L);
                line[i] = Line(point(U,y1),point(L,y2));
            }
            sort(line+1,line+n+1);
            line[0] = Line(point(x1,y1),point(x1,y2));
            int x,y;
            for(i = 0;i < m;i++){
                scanf("%d%d",&x,&y);
                int l = 0, r = n,tmp;
                while(l <= r){
                    int mid = l + r >> 1;
                    if( point(x,y).Xmult(line[mid].s,line[mid].t) <= 0) r = mid-1; //在线的上边
                    else tmp = mid,l = mid+1;   //线下的点所在的区域才是改line的标号;
                }
                ret[tmp]++;
            }
            for(i = 0;i <= n;i++){
                ans[ret[i]]++;
            }
            puts("Box");
            for(i = 1;i <= m;i++)if(ans[i])
                printf("%d: %d
    ",i,ans[i]);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    UVA1349 Optimal Bus Route Design 最优巴士路线设计
    POJ3565 Ants 蚂蚁(NEERC 2008)
    UVA1663 Purifying Machine 净化器
    UVa11996 Jewel Magic 魔法珠宝
    NEERC2003 Jurassic Remains 侏罗纪
    UVA11895 Honorary Tickets
    gdb调试coredump(使用篇)
    使用 MegaCLI 检测磁盘状态并更换磁盘
    员工直接坦诚直来直去 真性情
    山东浪潮超越3B4000申泰RM5120-L
  • 原文地址:https://www.cnblogs.com/hxer/p/5185148.html
Copyright © 2011-2022 走看看