POJ 2318 叉积判断点与直线位置
Description
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for John to find his favorite toys.
John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box.
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.
Input
Output
Sample Input
5 6 0 10 60 0
3 1
4 3
6 8
10 10
15 30
1 5
2 1
2 8
5 5
40 10
7 9
4 10 0 10 100 0
20 20
40 40
60 60
80 80
5 10
15 10
25 10
35 10
45 10
55 10
65 10
75 10
85 10
95 10
0
Sample Output
0: 2
1: 1
2: 1
3: 1
4: 0
5: 1 0: 2
1: 2
2: 2
3: 2
4: 2
Hint
记玩具在点p0,某块板的上边点是p1,下边点是p2,p2p1(向量)×p2p0>0表示p0在p1p2的左面,<0表示在右面。接下来就是用二分法找出每个点所在的分区。
叉积+二分查找
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6+, M = , mod = 1e9 + , inf = 0x3f3f3f3f;
typedef long long ll;
int n,m,x1,x2,y11,y2,ans[N],t1,t2;
struct point{int x,y;};
struct segment{point a,b;}s[N]; point sub(point a,point b) {//向量
point t;
t.x = a.x-b.x;
t.y = a.y-b.y;
return t;
}
int cross(point a,point b){//叉积公式
return a.x*b.y-b.x*a.y;
}
int turn(point p1,point p2,point p3){ //叉积
return cross(sub(p2,p1),sub(p3,p1));
}
void searchs(point x) {
int l=,r=n,mid,t=;
while(l<=r) {
mid = (l+r)>>;
if(turn(s[mid].a,s[mid].b,x) >= ) {
t = mid;l=mid+;
}
else r = mid-;
}
ans[t]++;
}
int main() {
while(scanf("%d",&n)&&n) {
memset(ans,,sizeof(ans));
scanf("%d%d%d%d%d",&m,&x1,&y11,&x2,&y2);
for(int i=;i<=n;i++){
scanf("%d%d",&t1,&t2);
s[i].a.x=t1;s[i].a.y=y11;
s[i].b.x=t2;s[i].b.y=y2;
}
for(int i=;i<=m;i++) {
point t;
scanf("%d%d",&t.x,&t.y);
searchs(t);
}
for(int i=;i<=n;i++)
printf("%d: %d\n",i,ans[i]);
printf("\n");
}
}
POJ 2318 叉积判断点与直线位置的更多相关文章
- POJ2318TOYS(叉积判断点与直线位置)
题目链接 题意:一个矩形被分成了n + 1块,然后给出m个点,求每个点会落在哪一块中,输出每块的点的个数 就是判断 点与直线的位置,点在直线的逆时针方向叉积 < 0,点在直线的顺时针方向叉积 & ...
- poj 2318(叉积判断点在线段的哪一侧)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13120 Accepted: 6334 Description ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- POJ 2318 (叉积) TOYS
题意: 有一个长方形,里面从左到右有n条线段,将矩形分成n+1个格子,编号从左到右为0~n. 端点分别在矩形的上下两条边上,这n条线段互不相交. 现在已知m个点,统计每个格子中点的个数. 分析: 用叉 ...
- poj 2398(叉积判断点在线段的哪一侧)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5016 Accepted: 2978 Descr ...
- POJ2318 TOYS(叉积判断点与直线的关系+二分)
Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...
- POJ 2398 map /// 判断点与直线的位置关系
题目大意: poj2318改个输出 输出 a: b 即有a个玩具的格子有b个 可以先看下poj2318的报告 用map就很方便 #include <cstdio> #include < ...
- poj2318(叉积判断点在直线左右+二分)
题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...
随机推荐
- 2015 Multi-University Training Contest 2 1006 Friends 壮压
题目链接 题意:t 组測试数据,每组測试数据有 n个人,m条关系 每条关系能够是 "线上关系" 或者 "线下关系". 要求每一个人的线上关系(条数) == 线下 ...
- 积跬步,聚小流------java信息生成图片
需求: 是在做证书的时候碰到的这个问题. 当时需求是能够进行在线打印证书,第一次进行的操作是直接打印html,并且已经排好版(用jqprint插件)进行打印.在打印时碰到了兼容的问题,另外因为背景图片 ...
- JavaScript——BOM(浏览器对象模型),时间间隔和暂停
BOM(浏览器对象模型):能够对浏览器的窗体进行訪问和操作 1.主要的BOM体系: window------------document-------------------------------- ...
- Pocket英语语法---六、感官动词接不同的动词表示什么意思
Pocket英语语法---六.感官动词接不同的动词表示什么意思 一.总结 一句话总结:其实进行时一般是表示连续,动词原形一般表示常态,过去分词一般表示被动(或者完成). 感官动词接原型表示动作的一般情 ...
- crawler4j多线程爬虫统计分析数据
该事例演示了如何在多线程中统计和分析数据: 首先建一个状态实体类CrawlStat: package com.demo.collectingData; /** * 爬虫状态实体类 统计爬虫信息 * @ ...
- 有关PHP数组
在PHP中,数组就是关键字和值的集合,我们可以使用array关键字创建: $arr=array[100,200,300,400,500]: //这是一个自定义数组,数组里面的值是自 ...
- Python中一些有用的小命令
1. 查看所有的关键字:help("keywords") 2.查看python所有的modules:help("modules") 3.单看python所有的m ...
- Hive 基本操作
1.创建一个表 (字段表名不加引号‘,分隔符需要加引号) create table t1( id int ,name string ,hobby array<string> ,add ma ...
- JWT加密
JWT是一种加密算法,为了防止请求的信息在传输途中被拦截修改 JWT的引用: install-package jwt JWF由三部分组成:Header,Payload,Signature Payloa ...
- Day 05 流程控制
流程控制 if 判断 语法: if if...else if...elif...else if判断是干什么的呢?if判断其实是在模拟人做判断.就是说如果这样干什么,如果那样干什么. if...else ...