2318 TOYS

2398 Toy Storage

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

思路 : 两个题基本差不多,只不过2398排一下序,然后再找个数组标记一下就行。

这个题我一开始没想到用二分,判断了点在四边形内但是没写下去,然后看了网上的二分区间,利用叉积判断点在左边还是右边。

2318代码:

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream> using namespace std ; struct point
{
int x,y ;
}p ;
struct line
{
point a,b ;
} eline[] ; int s[] ; int xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y) ;
} void binary_searc(point p,int a)
{
int l = , r = a- ,mid ;
while(l < r)
{
mid = (l + r) / ;
if(xmult(p,eline[mid].a,eline[mid].b) > ) l = mid+ ;
else r = mid ;
}
if(xmult(p,eline[l].a,eline[l].b) < ) s[l] ++ ;
else s[l+] ++ ;
}
int main()
{
int m,n,x1,x2,y1,y2 ;
while(scanf("%d",&n) != EOF)
{
if(n == ) break ;
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2) ;
memset(s,,sizeof(s)) ;
for(int i = ; i < n ; i++)
{
scanf("%d %d",&eline[i].a.x,&eline[i].b.x) ;
eline[i].a.y = y1 ;
eline[i].b.y = y2 ;
}
for(int i = ; i < m ; i++)
{
scanf("%d %d",&p.x,&p.y) ;
binary_searc(p,n) ;
}
for(int i = ; i <= n ; i++)
printf("%d: %d\n",i,s[i]) ;
printf("\n") ;
}
return ;
}

2398代码 :

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm> using namespace std ; struct point
{
int x,y ;
}p ;
struct line
{
point a,b ;
} eline[] ; int s[],s1[] ; int xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y) ;
} int cmp(const line &aa,const line &bb)
{
if (min(aa.a.x, aa.b.x) == min(bb.a.x, aa.b.x))
return max(aa.a.x, aa.b.x) < max(bb.a.x, bb.b.x);
return min(aa.a.x, aa.b.x) < min(bb.a.x, aa.b.x);
}
void binary_searc(point p,int a)
{
int l = , r = a- ,mid ;
while(l < r)
{
mid = (l + r) / ;
if(xmult(p,eline[mid].a,eline[mid].b) > ) l = mid+ ;
else r = mid ;
}
if(xmult(p,eline[l].a,eline[l].b) < ) s[l] ++ ;
else s[l+] ++ ;
}
int main()
{
int m,n,x1,x2,y1,y2 ;
while(scanf("%d",&n) != EOF)
{
if(n == ) break ;
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2) ;
memset(s,,sizeof(s)) ;
memset(s1,,sizeof(s1)) ;
for(int i = ; i < n ; i++)
{
scanf("%d %d",&eline[i].a.x,&eline[i].b.x) ;
eline[i].a.y = y1 ;
eline[i].b.y = y2 ;
}
sort(eline,eline+n,cmp) ;
for(int i = ; i < m ; i++)
{
scanf("%d %d",&p.x,&p.y) ;
binary_searc(p,n) ;
}
for(int i = ; i <= n ; i++)
s1[s[i]] ++ ;
printf("Box\n") ;
for(int i = ; i <= m ; i++)
{
if(s1[i] != )
printf("%d: %d\n",i,s1[i]) ;
}
// for(int i = 0 ; i <= n ; i++)
// printf("%d: %d\n",i,s[i]) ;
// printf("\n") ;
}
return ;
}

POJ 2318 TOYS && POJ 2398 Toy Storage(几何)的更多相关文章

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

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

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

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

  3. POJ 2318 TOYS/POJ 2398 Toy Storage

    计算几何终于开坑了... 叉积+二分. #include<iostream> #include<cstdio> #include<cstring> #include ...

  4. poj 2398 Toy Storage(计算几何)

    题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...

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

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

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

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

  7. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  8. POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

  9. POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]

    题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...

随机推荐

  1. Word 2003 出现 向程序发送命令时出现问题 的 解决方案

    这种原因出现的问题是word的模板出现问题. 解决方案是重新让word生成Norma.dot文档. 步骤: 1,按住视窗键+R或者开始菜单搜索文件和程序,粘贴 %appdata%\microsoft\ ...

  2. OC3_歌词解析

    // // LrcManager.h // OC3_歌词解析 // // Created by zhangxueming on 15/6/15. // Copyright (c) 2015年 zhan ...

  3. 从0开始学习react(三)

    这次我们来讲解第三节知识,考虑了下,先不去讲什么理论了,毕竟网上一搜一大堆,而且理论真心看不太懂啊!!! 今天我们就直接上实例喽! 大家HIGH起来!!!(想了好久,还是没舍得删这句话) 1.根据下图 ...

  4. HotSpot算法实现

    1.枚举根节点 可作为GC Roots的节点主要在全局性的引用(例如常量或类静态属性)与执行上下文(例如栈帧中的本地变量表)中. 可达性分析对执行时间的敏感体现在GC停顿上,因为分析工作必须在能确保一 ...

  5. 使用JavaScript实现简单的输入校验

    HTML页面代码: <!doctype html> <html lang="en"> <head> <meta charset=" ...

  6. Maven Dependency Scope用法

    原帖地址:http://uule.iteye.com/blog/2087485 官方API描述 Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个 ...

  7. apache重写

    ---- 本文旨在提供如何用Apache重写规则来解决一些常见的URL重写方法的问题,通过常见的实例给用户一些使用重写规则的基本方法和线索. 一.为什么需要用重写规则 ---- 网站的生命在于不断地进 ...

  8. laravel扩展xls处理maatwebsite/excel

    github地址:https://github.com/Maatwebsite/Laravel-Excel 安装: sudo composer require maatwebsite/excel 配置 ...

  9. CorelDRAW 文件实用工具 CDRTools 2

    随着 CorelDRAW 更新脚步越来越频繁,版本之间兼容性问题越来越突出,特别是跨版本之间打开会有很多问题,比如:文字跑位.透镜变向.位图出错.颜色改变,甚至会造成文件损坏.最好的办法就是哪一个版本 ...

  10. (转载)SQLServer存储过程返回值总结

    1. 存储过程没有返回值的情况(即存储过程语句中没有return之类的语句) 用方法 int count = ExecuteNonQuery(..)执行存储过程其返回值只有两种情况 (1)假如通过查询 ...