POJ 2398 Toy Storage(叉积+二分)
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
题意:与poj2318一样 统计每个隔断形成的区域内物品的数量
思路:叉积+二分 比poj2318多排序和统计的步骤
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int maxn=;
int n,m,x,y,xx,yy,tx,ty,U,L;
int ans[maxn],num[maxn]; 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);
}
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;
}
}line[maxn]; 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;
} int main(){
while(scanf("%d",&n)== && n){
scanf("%d%d%d%d%d",&m,&x,&y,&xx,&yy);
for(int i=;i<n;i++){
scanf("%d%d",&U,&L);
line[i]=Line(Point(U,y),Point(L,yy));
}
line[n]=Line(Point(xx,y),Point(xx,yy));
sort(line,line+n+,cmp);
Point p;
memset(ans,,sizeof(ans));
memset(num,,sizeof(num));
while(m--){
scanf("%d%d",&tx,&ty);
p=Point(tx,ty);
int l=,r=n;
int tmp;
while(l<=r){
int mid=(l+r)>>;
if(xmult(p,line[mid].s,line[mid].e)<){
tmp=mid;
r=mid-;
}
else l=mid+;
}
ans[tmp]++;
}
for(int i=;i<=n;i++){
if(ans[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 2398 Toy Storage(叉积+二分)的更多相关文章
- 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 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- poj 2398 Toy Storage【二分+叉积】
二分点所在区域,叉积判断左右 #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- 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 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- 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 点与直线位置关系
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5439 Accepted: 3234 Descr ...
随机推荐
- 小程序第三方框架对比 ( wepy / mpvue / taro )(转)
文章转自 https://www.cnblogs.com/Smiled/p/9806781.html 众所周知如今市面上端的形态多种多样,手机Web.ReactNative.微信小程序, 支付宝小程 ...
- 初学Kafka工作原理流程介绍
Apache kafka 工作原理介绍 消息队列技术是分布式应用间交换信息的一种技术.消息队列可驻留在内存或磁盘上, 队列存储消息直到它们被应用程序读走.通过消息队列,应用程序可独立地执行--它们不需 ...
- echarts中饼图显示百分比
通过echarts制作饼图,需要通过鼠标移动到对应的扇形才能才看数值和百分比. 解决这个问题参考的是将鼠标移动到扇形上的显示方法: tooltip : { trigger: ' ...
- sqlalchemy常用
一.SQLAlchemy 创建表 from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Colu ...
- windows平台上用python 远程线程注入,执行shellcode
// 转自: https://blog.csdn.net/Jailman/article/details/77573990import sys import psutil import ctypes ...
- 使用css画一个箭头
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- php的接口,抽象类,trait(转载,合并)
一. 抽象类abstract class 1 .抽象类是指在 class 前加了 abstract 关键字且存在抽象方法(在类方法 function 关键字前加了 abstract 关键字)的类. 2 ...
- c选择排序算法
void selectsort(int *a,int len) { int i,j; int temp; for(i=0;i<len-1;i++) { for(j=i+1;j<len;j+ ...
- Shell命令-文件及目录操作之file、md5sum
文件及目录操作 - file.md5sum 1. file:显示文件的类型 file命令的功能说明 用于辨识文件类型.通过 file 指令,我们得以辨识该文件的类型. file命令的语法格式 file ...
- CentOS修改SSH端口号和禁止root用户直接登录
linux安装ssh远程登录后,为了安全起见,修改默认的22端口号并禁止root用户直接通过ssh登录. 配置方法如下: 1.使用vi编辑器打开ssh配置文件 /etc/ssh/sshd_config ...