// 题意:问你每个区域有多少个点
// 思路:数据小可以直接暴力
// 也可以二分区间 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long LL;
const LL inf = 1e18;
const int N = ; struct Point{
int x,y;
Point(){}
Point(int _x,int _y){
x=_x;y=_y;
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
int operator *(const Point &b)const{
return x*b.x+y*b.y;
}
int operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
}; struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){
s=_s,e=_e;
}
}; int xmult(Point p0,Point p1,Point p2){
return (p1-p0)^(p2-p0);
} Line line[N];
int ans[N];
int main(){
int n,m,x1,y1,x2,y2;
bool first = true;
while(~scanf("%d",&n)&&n){
if(first) first=false;
else printf("\n");
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(int i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
line[i]=Line(Point(x,y1),Point(y,y2));
}
line[n]=Line(Point(x2,y1),Point(x2,y2));
int x,y;
Point p;
memset(ans,,sizeof(ans));
int tem;
while(m--){
scanf("%d%d",&x,&y);
p = Point(x,y);
int l=,r=n,mid;
while(l<=r){
mid=(l+r)>>;
if(xmult(p,line[mid].s,line[mid].e)<){
tem=mid;
r=mid-;
}
else l=mid+;
}
ans[tem]++;
}
for(int i=;i<=n;i++) printf("%d: %d\n",i,ans[i]);
}
return ;
}
 // POJ 2398和2318差不多 多了排序和统计输出

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
#include <cmath>
using namespace std;
typedef long long LL;
const LL inf = 1e18;
const int N = ; struct Point{
int x,y;
Point(){}
Point(int _x,int _y){
x=_x;y=_y;
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
int operator *(const Point &b)const{
return x*b.x+y*b.y;
}
int operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
}; struct Line{
Point s,e;
Line(){}
Line(Point _s,Point _e){
s=_s,e=_e;
}
}; int xmult(Point p0,Point p1,Point p2){
return (p1-p0)^(p2-p0);
} bool cmp(Line a,Line b){
return a.s.x<b.s.x;
} Line line[N];
int ans[N];
int num[N];
int main(){
int n,m,x1,y1,x2,y2;
while(~scanf("%d",&n)&&n){
memset(num,,sizeof(num));
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(int i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
line[i]=Line(Point(x,y1),Point(y,y2));
}
line[n]=Line(Point(x2,y1),Point(x2,y2));
sort(line,line+n+,cmp);
int x,y;
Point p;
memset(ans,,sizeof(ans));
int tem;
while(m--){
scanf("%d%d",&x,&y);
p = Point(x,y);
int l=,r=n,mid;
while(l<=r){
mid=(l+r)>>;
if(xmult(p,line[mid].s,line[mid].e)<){
tem=mid;
r=mid-;
}
else l=mid+;
}
ans[tem]++;
}
for(int i=;i<=n;i++){
num[ans[i]]++;
}
printf("Box\n");
for(int i=;i<=n;i++) {
if(num[i]>)
printf("%d: %d\n",i,num[i]);
}
}
return ;
}

二分+叉积判断方向 poj 2318 2398的更多相关文章

  1. POJ 2318/2398 叉积性质

    2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...

  2. POJ 2318--TOYS(二分找点,叉积判断方向)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17974   Accepted: 8539 Description ...

  3. TOYS - POJ 2318(计算几何,叉积判断)

    题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数.   分析:做的第一道计算几何题目....使用叉积判断方 ...

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

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

  5. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

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

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

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

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

  8. poj 2318(叉积判断点在线段的哪一侧)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13120   Accepted: 6334 Description ...

  9. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

随机推荐

  1. loadrunner使用system()函数调用Tesseract-OCR识别验证码遇到的问题

    俗话说前人栽树,后人乘凉,此话一点不假,结合云层的一遍文章:http://bbs.51testing.com/thread-533920-1-1.html,知道还有一个Tesseract-OCR可以用 ...

  2. 编译器的未来——我们还需要C++么?

    在未来我们还需要纯C++开发模式么? 随着C++11的诞生,C++已经越来越臃肿,从03的时候就觉得C++实在是太复杂了.以一个合格C++程序员的标准来简单的来说3-5年略有小成,5-8年才可以说自己 ...

  3. Photoshop:制作金属质感-不锈钢纹理

    效果图 过程: 1.滤镜->渲染->云彩 2.滤镜->模糊->高斯模糊 3.滤镜->杂色->添加杂色 ,数量10 4.滤镜->模糊->径向模糊 5.滤镜 ...

  4. makefile使用

    linux make手册:http://www.gnu.org/software/make/manual/make.html 一篇文章: 假设我们有一个程序由5个文件组成,源代码如下:/*main.c ...

  5. python生成验证码脚本

    最近每天都用python写一个小的脚本,练习使用python语法. 验证码的生成: 这里使用了python的图像处理库PIL,安装PIL的过程中出了一个小麻烦,就使用Pillow-win32的一个文件 ...

  6. 修改tabbarcontroller选中图片及选中颜色

    1.修改选中图片: UITabBarItem* item = [self.tabBarController.tabBar.items objectAtIndex:1];   //从0开始 item.s ...

  7. hibernate--query接口初步

    Query session.createQuery(String hql)方法; * hibernate的session.createQuery()方法是使用HQL(hibernate的查询语句)语句 ...

  8. 查看mssql死锁的详细信息(存储过程)

    CREATE  procedure [dbo].[sp_who_lock]asbegindeclare @spid int,@bl int,        @intTransactionCountOn ...

  9. UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)

    题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x ...

  10. WTL汉化版2013.10.15

    汉化内容: 2013.10.15 版本:当前可下载Trunk最新版,wtl-code-467-trunk.zip 汉化内容: 1.应用向导的部分汉化,考虑到部分词汇的表述问题,只汉化无影响部分 2.资 ...