TOYS

题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数。

思路:这道题很水,只是要知道会使用叉乘来表示点在线的上面还是下面;
当a.Xmult(b,c) < 0时,表示在线的上面。之后就是二分的时候,不能直接使用mid来ans[mid]++;

因为只是确定点在这条线的两边,到底是哪一边,具体还要用tmp来判断;(模板题)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
#define MS0(a) memset(a,0,sizeof(a))
const int MAXN = ;
struct point{
int x,y;
point(){}
point(int _x,int _y){
x = _x; y = _y;
}
long long operator *(const point &b)const{// 叉乘
return (1LL*x*b.y - 1LL*y*b.x);
}
point operator -(const point &b)const{
return point(x - b.x,y - b.y);
}
long long dot(const point &b){ //点乘
return 1LL*x*b.x + 1LL*y*b.y;
}
double dist(const point &b){
return sqrt(1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y));
}
long long dist2(const point &b){
return 1LL*(x-b.x)*(x-b.x)+1LL*(y-b.y)*(y-b.y);
}
double len(){
return sqrt(1LL*x*x+1LL*y*y);
}
double point_to_segment(point b,point c)//点a到“线段” bc的距离a.point_to_segment(b,c);
{
point v[];
v[] = {c.x - b.x,c.y - b.y};
v[] = {x - b.x,y - b.y};
v[] = {x - c.x,y - c.y};
if(v[].dot(v[]) < ) return v[].len();
if(v[].dot(v[]) > ) return v[].len();
return fabs(.*(v[]*v[])/v[].len());
}
long long Xmult(point b,point c){ // 当a->b与a->c顺时针转时,返回正;
return (b-*this)*(c-*this);
}
void input(){
scanf("%d%d",&x,&y);
}
}p[MAXN]; struct Line{
point s,t;
Line(){}
Line(point _s,point _t){
s = _s,t =_t;
}
}line[MAXN];
int ans[MAXN];
int main()
{
int n,m,i,j,x1,y1,x2,y2,kase = ,U,L;
while(scanf("%d",&n),n){
MS0(ans);
if(kase) puts("");
else kase++;
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
for(i = ;i <= n;i++){
scanf("%d%d",&U,&L);
line[i] = Line(point(U,y1),point(L,y2));
}
line[] = Line(point(x1,y1),point(x1,y2));
int x,y;
for(i = ;i < m;i++){
scanf("%d%d",&x,&y);
int l = , r = n,mid,tmp;
while(l <= r){
mid = l + r >> ;
if( point(x,y).Xmult(line[mid].s,line[mid].t) < ) r = mid-; //在线的上边
else tmp = mid,l = mid+; //线下的点所在的区域才是改line的标号;
}
ans[tmp]++; }
for(i = ;i <= n;i++){
printf("%d: %d\n",i,ans[i]);
}
}
return ;
}

poj 2318 TOYS的更多相关文章

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

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

  2. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  3. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  4. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

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

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

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

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

  7. POJ 2318 - TOYS - [计算几何基础题]

    题目链接:http://poj.org/problem?id=2318 Time Limit: 2000MS Memory Limit: 65536K Description Calculate th ...

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

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

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

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

随机推荐

  1. 【05】了解C++默默编写并调用那些函数

    1.如果没有声明copy构造方法,copy赋值操作符,和析构方法,编译器会自动生成这些方法,且是inline. 2.如果没有声明任何构造方法,编译器会自动生成一个default构造方法,且是inlin ...

  2. Sublime 格式化代码 快捷键以及插件使用

    来自Vic___:http://blog.csdn.net/vic___ 其实在sublime中已经自建了格式化按钮: Edit  ->  Line  ->  Reindent 只是sub ...

  3. Project interpreter not specified(eclipse+pydev)

    [小记] 近期由于想配置Android的开发环境,把原来的MyEclipse5.5删了,下载了最新的Eclipse3.7版本号,由于之前在进行Python开发,就下载了最新的Pydev2.4版本号,安 ...

  4. careercup-树与图 4.1

    4.1 实现一个函数,检查二叉树是否平衡.在这个问题中,平衡树的定义如下:任意一个结点,其两颗子树的高度差不超过1. C++实现代码: #include<iostream> #includ ...

  5. 导演类(CCDirector)

  6. zTree下拉菜单多级菜单多选实现

    惯例,先上图: 这是在一个项目中,为了满足样式美观.多级菜单以及多选而将zTree插件更改过后的效果. 在实际的开发过程中,本来zTree也是可以满足需求的,但是zTree多选的话需要checkbox ...

  7. Java基础知识强化之集合框架笔记74:各种集合常见功能 和 遍历方式总结

    1. Collection add() remove() contains() iterator() size() 遍历: 增强for 迭代器 |--List get() 遍历: 普通for |--S ...

  8. UISenior之数据的本地化持久化

    数据的本地化主要分为两个方面:1.简单数据的本地持久化(NSString.NSArray.NSDictionary.NSData)2.复杂数据的本地持久化(本文以Person类为例) 简单对象的本地化 ...

  9. magento flat和eav表连接的不同

    对于flat表,也就是普通的表,例如订单之类的sales_flat_order,这类型的连接,Collection连接 $table = Mage::getSingleton('core/resour ...

  10. JQuery设置input属性(disabled、enabled)

    document.getElementById("removeButton").disabled = false; //普通Js写法 $("#removeButton&q ...