// 题意:问你每个区域有多少个点
// 思路:数据小可以直接暴力
// 也可以二分区间 #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. linux下安装Apache(https) 服务器证书安装配置指南

    一.  安装准备 1.    安装Openssl 要使Apache支持SSL,需要首先安装Openssl支持.推荐下载安装openssl-0.9.8k.tar.gz   下载Openssl:http: ...

  2. android从应用到驱动之—camera(2)---cameraHAL的实现

    本文是camera系列博客,上一篇是: android从应用到驱动之-camera(1)---程序调用流程 本来想用这一篇博客把cameraHAL的实现和流程都给写完的.搞了半天,东西实在是太多了.这 ...

  3. 【c++】中文设置

    #include <iostream> #include <string> #include<locale> using namespace std; ; int ...

  4. linux下文件夹的创建、复制、剪切、重命名、清空和删除命令

    在home目录下有wwwroot目录,wwwroot下有sinozzz目录,即/home/wwwroot/sinozzz 一.目录创建 在/home/wwwroot目录下新建一个sinozzz123的 ...

  5. jQuery EasyUI - Add link to datagrid cell

    Extracted from: http://stackoverflow.com/questions/16061894/jquery-easyui-add-link-to-cell HTML: < ...

  6. C++ STL之迭代器注意事项

    1.两个迭代器组成的区间是前闭后开的 2.如果迭代器的有效性,如果迭代器所指向的元素已经被删除,那么迭代器会失效 http://blog.csdn.net/hsujouchen/article/det ...

  7. UVa 10892 (GCD) LCM Cardinality

    我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...

  8. Asp.Net MVC Filter权限过滤使用说明

    相信对权限过滤大家都不陌生,用户要访问一个页面时,先对其权限进行判断并进行相应的处理动作. mvc中是如何实现权限验证的? mvc中是根据路由配置来请求控制器类中的一个方法 在mvc框架中为程序员提供 ...

  9. Java 7 语法新特性

    一.二进制数字表达方式 原本整数(以60为例)能够用十进制(60).八进制(074).十六进制(0x3c)表示,唯独不能用二进制表示(111100),Java 7 弥补了这点. public clas ...

  10. qq互联(connect.qq.com)取用户信息的方法

    <?php //应用的APPID$app_id = "YOUR_APP_ID";//应用的APPKEY$app_secret = "YOUR_APP_KEY&quo ...