• POJ 2398 Toy Storage


    题意:

    给你一些玩具,找出有t个玩具的区间个数。

    题解:

    poj2318的简单进阶,区别:隔断无序,需要对这些分段进行排序。然后哈希存具有t个玩具的区间。

    代码:

    #include <stdio.h>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #include <queue>
    #include <map>
    #include <list>
    #include <utility>
    #include <set>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #define mem(arr,num) memset(arr,0,sizeof(arr))
    #define _for(i, a, b) for(int i = a; i <= b; i++)
    #define __for(i, a, b) for(int i = a; i >=b; i--)
    #define IO ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
    using namespace std;
    typedef long long ll;
    typedef vector<int > vi;
    const ll INF = 0x3f3f3f3f;
    const int mod = 1e9 + 7;
    const int N = 5000 + 5;
    struct P
    {
        int x,y;
        P() {}
        P(int a, int b)
        {
            x = a, y = b;
        }
        P operator- (P b)
        {
            return P(x-b.x,y-b.y);
        }
    } L,R,p[N];
    pair <P, P> pr;
    vector<pair<P, P> > line;
    double cross(P a, P b) {
        return a.x * b.y - a.y * b.x;
    }
    double judge(P c, P a, P b){
        return cross(c - a,b - a);
    }
    int res[N],ans[N];
    bool cmp(pair<P,P> a,pair<P,P> b){
        return a.first.x < b.first.x;
    }
    int main()
    {
        int n, m;
        while(cin >> n, n)
        {
            mem(res,0);
            mem(ans,0);
            line.clear();
            cin >> m >> L.x >> L.y >> R.x >> R.y;
            pr.second = L;
            pr.first.x = L.x, pr.first.y = R.y;
            line.push_back(pr);
            _for(i, 1, n)
            {
                int a, b;
                P p;
                cin >> a >> b;
                p.x = a, p.y = L.y;
                pr.second = p;
                p.x = b, p.y = R.y;
                pr.first = p;
                line.push_back(pr);
            }
            pr.second.x = R.x, pr.second.y = L.y;
            pr.first = R;
            line.push_back(pr);
            sort(line.begin(),line.end(),cmp);
            _for(i, 1, m) cin >> p[i].x >> p[i].y;
            _for(i, 1, m) {
                int l = 0, r = line.size()-1,mid;
                while(r - l != 1){
                    mid = (l+r)/2;
                    P _x = line[mid].first,_y = line[mid].second;
                    if(judge(p[i], _x, _y)<0) r = mid;
                    else l = mid;
                }
                res[l] ++;
            }
            _for(i, 0, n)
                ans[res[i]]++;
            cout << "Box" << endl;
            _for(i, 1, n)
                if(ans[i])
                cout << i <<": "<< ans[i] <<endl;
        }
        return 0;
    }
    宝剑锋从磨砺出 梅花香自苦寒来
  • 相关阅读:
    RabbitMQ使用教程(一)RabbitMQ环境安装配置及Hello World示例
    Spring入门(四):使用Maven管理Spring项目
    Java基础知识常见面试题汇总 第三篇
    Java基础知识常见面试题汇总 第二篇
    Java基础知识常见面试题汇总 第一篇
    程序员如何巧用Excel提高工作效率 第二篇
    程序员如何巧用Excel提高工作效率
    数据库管理工具DataGrip使用总结(一)
    MySql给表添加列和注释
    Spring入门(三):通过JavaConfig装配bean
  • 原文地址:https://www.cnblogs.com/GHzcx/p/8798148.html
Copyright © 2020-2023  润新知