题目链接

题意:

给定一个矩形,n个线段将矩形分成n+1个区间,m个点,问这些点的分布。

题解:

思路就是叉积加二分,利用叉积判断点与直线的距离,二分搜索区间。

代码:

最近整理了STL的一些模板,发现真是好用啊orz,为啥以前没发现呢,可能是比较懒吧-.-

#include <stdio.h>
#include <string.h>
#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--)
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
+;
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];
int main()
{
    int n, m;
    while(cin >> n, n)
    {
        mem(res,);
        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, , 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);
        _for(i, , m) cin >> p[i].x >> p[i].y;
        _for(i, , m) {
            , r = line.size()-,mid;
            ){
                mid = (l+r)/;
                P _x = line[mid].first,_y = line[mid].second;
                ) r = mid;
                else l = mid;
            }
            res[l] ++;
        }
        _for(i, , n)
            cout << i <<": "<< res[i] <<endl;
        cout << endl;
    }
    ;
}

POJ 2318 TOYS(点与直线的关系 叉积&&二分)的更多相关文章

  1. poj 2318 TOYS 点与矩形的关系

    题目链接 题意 有一个矩形盒子,\(n(n\leq 5e4)\)条线段将其分成了\(n+1\)个区域(每条线段的两个端点分别在矩形的上边和下边,且线段互不相交).现向盒子中扔\(m(m\leq 5e4 ...

  2. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  3. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  4. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  5. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  6. POJ 1269 Intersecting Lines (判断直线位置关系)

    题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...

  7. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  8. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  9. POJ 2318 /// 判断点与直线的位置关系

    题目大意: n块玩具箱隔板 m个玩具落地点 给定玩具箱的左上和右下两个端点 接下来给定n块隔板的上点的x和下点的x(因为y就是玩具箱的上下边缘) 接下来给定m个玩具落地点 输出n+1个区域各有的玩具数 ...

随机推荐

  1. HDU3265 线段树(扫描线)

    Posters Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  2. (译)理解python线程

    看到一篇老外写的线程文章,很赞,零基础都能看懂.先贴在这里,有时间再翻译出来. http://agiliq.com/blog/2013/09/understanding-threads-in-pyth ...

  3. Ajax请求回调函数没有被调用

    $.ajax({        type:"post",        url:"http://172.16.41.91:8080/FcsServletSSM/users ...

  4. Linux常用命令汇总(持续更新中)

    命令 说明 注意点 cat access.log | wc -l 统计行数 awk命令可以做到同样的想过:cat access.log | awk 'END {print NR}' grep vnc  ...

  5. Java程序运行时的几个区域

    Java运行时涉及到的区域 几个基本概念: 1.Java对象     2.Java方法    3.一个编译好的类,以class文件的形式出现 4.Java的本地方法   5.线程私有和线程共有   一 ...

  6. codeforces——contest 864 problemE

    Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable it ...

  7. https 多路复用的理解~转载

    https://segmentfault.com/q/1010000005167289 这里面的http/2连接是指tcp/ip层的连接还是http应用层(也就是我们平常在chrome F12 net ...

  8. 通过编译函数库来学习GCC【转】

    转自:http://blog.csdn.net/u012365926/article/details/51446295 基本概念 什么是库 在windows平台和linux平台下都大量存在着库. 本质 ...

  9. 网络知识===wireshark抓包数据分析(一)

    wireshark分析: 上图是我进行一个HTTP协议的下载,文件内容大概是1.7M左右. 抓包数据: https://files.cnblogs.com/files/botoo/wireshark% ...

  10. mount/umount命令【转】

    转自:http://www.cnblogs.com/qq78292959/archive/2012/03/06/2382334.html 如果想在运行的Linux下访问其它文件系统中的资源的话,就要用 ...