zoukankan      html  css  js  c++  java
  • POJ 2398 map /// 判断点与直线的位置关系

    题目大意:

    poj2318改个输出

    输出 a: b 即有a个玩具的格子有b个

    可以先看下poj2318的报告

    用map就很方便

    #include <cstdio>
    #include <cmath>
    #include <string.h>
    #include <algorithm>
    #include <map>
    using namespace std;
    const double eps=1e-10;
    const int N=1000+5;
    double add(double a,double b)
    {
        if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
        return a+b;
    }
    struct P {
        double x,y;
        P(){};
        P(double _x,double _y):x(_x),y(_y){};
        P operator - (P p) {
            return P(add(x,-p.x),add(y,-p.y)); };
        P operator + (P p) {
            return P(add(x,p.x),add(y,p.y)); };
        P operator * (double d) {
            return P(x*d,y*d); };
        double dot (P p) {
            return add(x*p.x,y*p.y); };
        double det (P p) {
            return add(x*p.y,-y*p.x); };
    }st,ed,a[N],toy;
    map <int,int> mp, ans;
    int n, m;
    bool cmp(P a,P b) {
        if(a.x==b.x) return a.y<b.y;
        return a.x<b.x;
    }
    int main()
    {
        while(~scanf("%d",&n)) {
            if(n==0) break;
            scanf("%d%lf%lf%lf%lf",&m,&st.x,&st.y,&ed.x,&ed.y);
            for(int i=0;i<n;i++)
                scanf("%lf%lf",&a[i].x,&a[i].y);
            a[n].x=ed.x, a[n].y=ed.y;
            sort(a,a+1+n,cmp);
            mp.clear(); ans.clear();
            for(int i=0;i<m;i++) {
                scanf("%lf%lf",&toy.x,&toy.y);
                int k=0;
                while((toy-P(a[k].x,st.y)).det(P(a[k].y,ed.y)-toy)<0) k++;
                mp[k]++; /// mp记录每个格子对应的玩具数量
            }
            printf("Box
    ");
            map <int,int> :: iterator it;
            for(it=mp.begin();it!=mp.end();it++)
                ans[it->second]++; /// 遍历mp ans记录每种玩具数量对应的格子数
            for(it=ans.begin();it!=ans.end();it++)
                printf("%d: %d
    ",it->first,it->second);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    大数据测试2
    大数据测试3
    CROSS APPLY和 OUTER APPLY 区别详解
    SQL中的escape的用法
    Sql Server参数化查询之where in和like实现详解
    多行文本框换行符处理
    Cross Apply的用法
    交叉连接Cross Join的用法
    统计字符串中某个字符的个数
    JOIN用法
  • 原文地址:https://www.cnblogs.com/zquzjx/p/9607828.html
Copyright © 2011-2022 走看看