题目链接

题意:

给定一个矩形,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. CentOS 下安装 LEMP 服务(nginx、MariaDB/MySQL 和 php)

    转载自:https://linux.cn/article-4314-1.html 编译自:http://xmodulo.com/install-lemp-stack-centos.html 作者: D ...

  2. Hadoop 介绍

    1.Hadoop简介 Hadoop[hædu:p]实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有高容错性的特点,并且设计用来部署在低 ...

  3. Android之简易音乐播发器

    布局主要代码之ListView: <span style="font-size:14px;"> <ListView android:id="@+id/m ...

  4. linux包安装,解压,压缩,包管理,环境变量

    linux 包安装,解压,压缩,包管理 centoscentos上有系统包管理器yum yum的配置一般有两种方式,一种是直接配置/etc目录下的yum.conf文件,另外一种是在/etc/yum.r ...

  5. 图论:Prufer编码-Cayley定理

    BZOJ1430:运用Cayley定理解决树的形态统计问题 由Prufer编码可以引申出来一个定理:Cayley 内容是不同的n结点标号的树的数量为n^(n-2) 换一种说法就是一棵无根树,当知道结点 ...

  6. 【BZOJ4870】组合数问题 [矩阵乘法][DP]

    组合数问题 Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description Input 第一行有四个整数 n ...

  7. 【洛谷 P4320】 道路相遇 (圆方树,LCA)

    题目链接 题意:给一张无向图和\(M\)个询问,问\(u,v\)之间的路径的必经之点的个数. 对图建出圆方树,然后必经之点就是两点路径经过的原点个数,用\((dep[u]+dep[v]-dep[LCA ...

  8. mybatis 插入语句name no find

    1.可参考连接:https://www.cnblogs.com/thomas12112406/p/6217211.html 2.dao层的配置 void addUser(@Param("un ...

  9. html+js+node实现五子棋线上对战,五子棋最简易算法

    首先附上我的github地址,https://github.com/jiangzhenfei/five,线上实例:http://47.93.103.19:5900/client/ 线上实例,你可以随意 ...

  10. F题 hdu 1431 素数回文

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1431 素数回文 Time Limit: 2000/1000 MS (Java/Others)    M ...