POJ 2318 TOYS(点与直线的关系 叉积&&二分)
题目链接
题意:
给定一个矩形,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(点与直线的关系 叉积&&二分)的更多相关文章
- poj 2318 TOYS 点与矩形的关系
题目链接 题意 有一个矩形盒子,\(n(n\leq 5e4)\)条线段将其分成了\(n+1\)个区域(每条线段的两个端点分别在矩形的上边和下边,且线段互不相交).现向盒子中扔\(m(m\leq 5e4 ...
- POJ 2318 TOYS(叉积+二分)
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...
- 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage
题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...
- poj 2318 TOYS (二分+叉积)
http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 101 ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- POJ 1269 Intersecting Lines (判断直线位置关系)
题目链接:POJ 1269 Problem Description We all know that a pair of distinct points on a plane defines a li ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- POJ 2318 /// 判断点与直线的位置关系
题目大意: n块玩具箱隔板 m个玩具落地点 给定玩具箱的左上和右下两个端点 接下来给定n块隔板的上点的x和下点的x(因为y就是玩具箱的上下边缘) 接下来给定m个玩具落地点 输出n+1个区域各有的玩具数 ...
随机推荐
- JN5169 --------- zigbee代码
队列: 需要创建3个标准队列(只创建不使用): ------Queue with handle zps_msgMlmeDcfmInd to receive IEEE 802.15.4 MACcomma ...
- [freemarker篇]01.入门Freemarker示例
这今天“弄”军哥的管理系统,里面由涉及到一部分的FreeMarker的知识,并且我那些学生在亚信实习也涉及到这部分的知识,所以想开始总结一些FreeMarker,正好我可开始使用一下Maven,简单的 ...
- js:鼠标移动到文字显示div,移出文字div显示,鼠标能移进div
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...
- hdu 4903 The only survival
The only survival http://acm.hdu.edu.cn/showproblem.php?pid=4903 Time Limit: 40000/20000 MS (Java/Ot ...
- linux下安装tomcat8
1.自己电脑下载好jdk的linux版本传到linux上或者直接用wget命令下载 安装文件放上去,用ls命令查看下载后的文件,看到apache-tomcat-8.0.28.tar.gz就是我们下载来 ...
- Linux powercli 以及connect-viserver 连接问题
1. 参考文档 http://fdo-workspace.blogspot.hk/2017/07/powershell-powercli-for-linux-server.html 2. powers ...
- 【spoj1182/usaco-Cow Queueing, 2003 Dec-二进制编号】数位dp
题意:定义新的排序:先按一个数中二进制中1的个数从小到大排序,如果1的个数相同则按数的大小从小到大排序.问[A,B]之间有第K大的数是哪个.-2^31<=A,B<=2^31(A,B必定同正 ...
- 4、什么是事务?MySQL如何支持事务?
什么是事务? 事务是由一步或几步数据库操作序列组成逻辑执行单元,这系列操作要么全部执行,要么全部放弃执行.程序和事务是两个不同的概念.一般而言:一段程序中可能包含多个事务.(说白了就是几步的数据库操作 ...
- Android 聊天软件客户端
1.代码架构图 2.qq.model层 3.qq.app层 4.qq.Constatnt层 5.qq.util层 6.qq.broadcast层 7.qq.control层 8.qq.view层 9. ...
- tex src
https://github.com/jepsonr/Text-Exercises https://github.com/Khan/KaTeX https://github.com/goldsboro ...