POJ 2398--Toy Storage(叉积判断,二分找点,点排序)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6534 | Accepted: 3905 |
Description
Reza's parents came up with the following idea. They put cardboard partitions into the box. Even if Reza keeps throwing his toys into the box, at least toys that get thrown into different partitions stay separate. The box looks like this from the top:

We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.
Input
A line consisting of a single 0 terminates the input.
Output
Sample Input
4 10 0 10 100 0
20 20
80 80
60 60
40 40
5 10
15 10
95 10
25 10
65 10
75 10
35 10
45 10
55 10
85 10
5 6 0 10 60 0
4 3
15 30
3 1
6 8
10 10
2 1
2 8
1 5
5 5
40 10
7 9
0
Sample Output
Box
2: 5
Box
1: 4
2: 1
Source
- 题意:给定n条无顺序的边,将一个矩形划分成n+1个区域,再给定m个点,求每个区域各有多少个点,输出将按区域内存在的点的数目进行升序排序。
和POJ2318类似,但是这里的点需要排序,还有输出结果不同 - code:
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
const int MAX = ;
typedef struct point {
int x;
int y;
}point;
typedef struct value {
point start;
point end;
}v;
v edge[MAX];
int sum[MAX], ans[MAX];
int n, m, x1, y11, x2, y2, flag = ,Ui, Li;
point tp;
int Xj, Yj;
bool com(const v t1, const v t2) {
return t1.start.x < t2.start.x;
}
bool com2(const int a, const int b) {
return a < b;
}
int multi(point p1, point p2, point p0) { //判断p1p0和p2p0的关系,<0,p1p0在p2p0的逆时针方向
return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);
}
void inset(point p) {
int low = , high = n;
while (low <= high) {
int mid = (high + low) / ;
if (multi(p, edge[mid].start, edge[mid].end) < ) /*点p1在边的左侧*/
high = mid - ;
else //点p在边的右侧
low = mid + ;
}
if (multi(p, edge[low-].start, edge[low-].end) < )
sum[low-]++;
else
sum[low]++;
}
int main() {
while (cin>>n && n) {
memset(sum, , sizeof(sum));
memset(ans, , sizeof(ans));
cin >> m >> x1 >> y11 >> x2 >> y2;
for (int i = ; i < n; i++) {
cin >> Ui >> Li;
edge[i].start.x = Ui;
edge[i].start.y = y11;
edge[i].end.x = Li;
edge[i].end.y = y2;
}
edge[n].start.x = x2;
edge[n].start.y = y11;
edge[n].end.x = x2;
edge[n].end.y = y2;
sort(edge, edge + n + , com);
for (int j = ; j < m; j++) {
cin >> Xj >> Yj;
tp.x = Xj;
tp.y = Yj;
inset(tp);
}
for (int i = ; i <= n; i++)
{
if (sum[i] != )
ans[sum[i]]++;
}
cout << "Box" << endl;
for (int i = ; i <= n; i++)
{
if (ans[i] != )
cout << i << ": " << ans[i] << endl;
}
}
return ;
} - 再熟悉一下叉积函数
再熟悉一下叉积函数
int multi(point p1, point p2, point p0) {
return (p1.x - p0.x)*(p2.y - p0.y) - (p2.x - p0.x)*(p1.y - p0.y);
}
//判断p1p0和p2p0的关系
//结果<0, p1p0在p2p0的逆时针方向,即点p1在p2p0的左侧
//结果>0, p1p0在p2p0的顺时针方向,即点p1在p2p0的右侧
POJ 2398--Toy Storage(叉积判断,二分找点,点排序)的更多相关文章
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- poj 2398 Toy Storage(计算几何)
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3146 Accepted: 1798 Descr ...
- POJ 2398 Toy Storage(叉积+二分)
Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...
- poj 2398 Toy Storage【二分+叉积】
二分点所在区域,叉积判断左右 #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- POJ 2398 - Toy Storage 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
随机推荐
- mysql忘记root密码的解决方法
Windows下mysql忘记root密码的解决方法 1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:net stop mysql 或者在windows任 ...
- Google Kickstart在线测试规则以及注意事项
谷歌招聘在如火如荼的进行中,进谷歌都需要经过谷歌kickstart在线测试,然后过了之后还有五轮的面试- -.好吧毕竟你待遇高,你强你有理.. 下面介绍一下进谷歌的第一关google kickstar ...
- CSS 兼容性支持
CSS 兼容性支持 在一个CSS属性还没有成为标准之前,各浏览器厂商已经做了这个属性的实现,可能各浏览器实现不尽相同,所以加入属性前缀区分. safari , chrome:-webkit- oper ...
- matlab练习程序(广度优先搜索BFS、深度优先搜索DFS)
如此经典的算法竟一直没有单独的实现过,真是遗憾啊. 广度优先搜索在过去实现的二值图像连通区域标记和prim最小生成树算法时已经无意识的用到了,深度优先搜索倒是没用过. 这次单独的将两个算法实现出来,因 ...
- JS实现“双色球”
需求: 双色球玩法简单介绍: “双色球”彩票投注区分为红色球号码区和蓝色球号码区.每注投注号码由6个红色球号码和1个蓝色球号码组成.红色球号码从1--33中选择:蓝色球号码从1--16中选择.程序要求 ...
- Linux文件寻址算法:逻辑地址到物理地址的转换
题目描述: 编写一个函数实现Linux文件寻址的算法,即读取文件当前位置到物理存储位置的转换函数,需要给出运行的测试数据,可以假设和模拟需要的数据和结构.即编写一个函数unsigned long lt ...
- 再学UML-UML用例建模解析(二)
(1) 关联关系 关联关系是指执行者与用例之间的关系,又称为通信关系,如果某个执行者可以对某个用例进行操作,它们之间就具有关联关系,如下图所示,“经理”有一个功能为“查看库存报表”,因此可以在执行者“ ...
- Scrum第三次冲刺
1.第三次冲刺任务概述 我们设计的长大万能通系统主要实现以下几个功能: a.周边查询 b.快递代取 c.查看校内新闻动态 d.二手物品交易 第三次冲刺我们计划实现周边查询功能.可以根据评分.距离最近. ...
- Jmeter入门10 jmeter加密串处理方式2:BeanShell PreProcessor
上一个博客讲了方式一:函数助手__digest加密,BeanShell PreProcessor也可以用java代码进行处理 线程组.参数.请求都直接使用上一个博客的. 第一步 添加BeanShell ...
- 笔记本win8系统共享wifi上网方法
华硕笔记本电脑,安装了win8系统,使用wifi上网,由于连接无线路由的机器太多,超过路由连接数上限,因此转为使用笔记本共享wifi方式给手机上网. 最终上网方式为: 笔记本网卡接入无线路由器上网,笔 ...