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. Linux crontab 命令格式与具体样例

    基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用*或者 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4列表示 ...

  2. javaweb之Filter详解(转)

    .概念: Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源: 例如Jsp, Servlet, 静态图片文件 ...

  3. java.sql.SQLException: Lock wait timeout exceeded --转

    org.springframework.dao.CannotAcquireLockException 的解决> 直接上 bug 的详细信息: 2012-03-12 15:20:31 XmlBea ...

  4. (原创)speex与wav格式音频文件的互相转换

    我们的司信项目又有了新的需求,就是要做会议室.然而需求却很纠结,要继续按照原来发语音消息那样的形式来实现这个会议的功能,还要实现语音播放的计时,暂停,语音的拼接,还要绘制频谱图等等. 如果是wav,m ...

  5. maven项目在tomcat中运行遇到的问题

    在使用maven构建项目,并在tomcat容器中运行的时候遇到了一些问题,现做一下记录 maven项目中jdk版本会自动恢复 maven项目的编译jdk即使在window -> java -&g ...

  6. 通过ApplicationContextAwareSpring实现手工加载配置的javabean

    在做一个多线程的数据采集器实现的过程中,由于框架是集成srping,因此希望统一使用原有的数据库配置信息,但是需要手工获取数据库配置bean.我们可以通过继承ApplicationContextAwa ...

  7. ECMA5 Array 新增API reduce

    1)reduce:相当与迭代: [].reduce(function(previous,current,index,array){ return previous * current;//相当与做阶乘 ...

  8. react中的坑

    9. 渲染界面的时候让滚动条回到顶部 //渲染界面的时候让滚动条回到顶部 componentDidMount() { window.scrollTo(0,0); } 路由: <Route pat ...

  9. c# winform实现网页上用户自动登陆,模拟网站登录

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  10. MSSQL的sysprocesses

          包含正在 SQL Server 实例上运行的进程的相关信息. 这些进程可以是客户端进程或系统进程. 若要访问 sysprocesses,您必须位于 master 数据库上下文中, 或者必须 ...