POJ - 2398 Toy Storage————计算几何

线段树入门学习(三)懒操作(兼解POJ1823) JAVA NULL 博文链接:https://128kj.iteye.com/blog/1739733 立即下载

Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for Reza to find his favorite toys anymore.
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
The input consists of a number of cases. The first line consists of six integers n, m, x1, y1, x2, y2. The number of cardboards to form the partitions is n (0 < n <= 1000) and the number of toys is given in m (0 < m <= 1000). The coordinates of the upper-left corner and the lower-right corner of the box are (x1, y1) and (x2, y2), respectively. The following n lines each consists of two integers Ui Li, indicating that the ends of the ith cardboard is at the coordinates (Ui, y1) and (Li, y2). You may assume that the cardboards do not intersect with each other. The next m lines each consists of two integers Xi Yi specifying where the ith toy has landed in the box. You may assume that no toy will land on a cardboard.

A line consisting of a single 0 terminates the input.
Output
For each box, first provide a header stating “Box” on a line of its own. After that, there will be one line of output per count (t > 0) of toys in a partition. The value t will be followed by a colon and a space, followed the number of partitions containing t toys. Output will be sorted in ascending order of t for each box.
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


#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=5000+5;
struct node{
    int x,y;
    node(){}
    node(int _x,int _y)
    {
        x=_x;
        y=_y;
    }
}p[MAXN];
struct line{
    node s,e;
    line(){}
    line(node _s,node _e)
    {
        s=_s;
        e=_e;
    }
}l[MAXN];

bool cmp1(node a,node b)
{
    return a.x==b.x?a.y<b.y:a.x<b.x;
}

int dir(node p1,node p2,node p3)//
{
    return (p3.x-p1.x)*(p2.y-p1.y)-(p2.x-p1.x)*(p3.y-p1.y);
}
bool cmp2(line a,line b)
{
    node n=a.s;
    node m=b.s;
    return n.x<m.x;
}
bool cmp3(int x,int y)
{
    return x>y;
}
int main()
{
    int n,m,x1,x2,y1,y2;
    int k=1;
    while(~scanf("%d",&n)&&n)
    {
//      if(k)   k=0;
//      else    printf("\n");
        int a[MAXN];
        memset(a,0,sizeof(a));
        scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
        l[0]=line(node(x1,y1),node(x1,y2));
        for(int i=1;i<=n;i++)
        {
            int x_1,x_2;
            scanf("%d %d",&x_1,&x_2);
            l[i]=line(node(x_1,y1),node(x_2,y2));
        }
        l[n+1]=line(node(x2,y1),node(x2,y2));
        for(int i=0;i<m;i++)
        {
            int x,y;
            scanf("%d %d",&x,&y);
            p[i]=node(x,y);
        }
        sort(p,p+m,cmp1);
        sort(l,l+n+2,cmp2);
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<=n;j++)
            {
                if((dir(p[i],l[j].s,l[j].e)>0&&dir(p[i],l[j+1].s,l[j+1].e)<0)||(dir(p[i],l[j].s,l[j].e)<0&&dir(p[i],l[j+1].s,l[j+1].e)>0))
//              if(dir(p[i],l[j].s,l[j].e) * dir(p[i],l[j+1].s,l[j+1].e)<0)
                {
                    a[j]++;
                    break;
                }
            }
        }

        map<int,int> ma;
        for(int i=0;i<n+1;i++)
            ma[a[i]]++;

//      sort(a,a+n+1,cmp3);
        printf("Box\n");
        for(map<int,int>::iterator ite=ma.begin();ite!=ma.end();ite++)
        {
            if(ite->first==0)   continue;
            printf("%d: %d\n",ite->first,ite->second);
        }

//      for(int i=0;i<n+1;i++)
//          printf("%d: %d\n",i,a[i]);
    }
    return 0;
}
RK3588 平台部署实战:OpenCV + LibTorch + FFmpeg 环境搭建与深度学习推理全流程解析 现在,你已经掌握了在RK3588上搭建OpenCV+LibTorch+FFmpeg环境的完整流程,也完成了深度学习模型的部署测试。不妨从一个具体的应用场景入手(如检测自家宠物的品种),亲手打造属于你的第一个边缘智能应用——当你看到模型在RK3588上精准输出结果时,你会发现:嵌入式深度学习的门槛,其实并没有想象中那么高。这些依赖是编译OpenCV、FFmpeg的基础,安装过程中若提示权限不足,可在命令前加。若能输出预测的类别索引,则说明环境搭建成功,模型推理流程通畅。文件,实现模型加载、图像预处理与推理。 阅读详情

相关推荐

实测对比:DJI O3、Walksnail Avatar、HDZero三大高清图传,谁才是低延迟王者?

本文对DJI O3、Walksnail Avatar V2和HDZero三大高清图传系统进行了实测对比,重点分析其在FPV飞行中的低延迟表现。通过专业测试环境和量化数据,揭示HDZero在原生低延迟架构上的优势,DJI O3在画质与延迟间的平衡,以及Walksnail的动态码率调整特点,为不同场景下的选购提供决策依据。

weixin_30756499的博客 446

QGIS二次开发踩坑实录:从Anaconda安装到解决GDAL的PROJ报错(完整避坑指南)

本文详细介绍了QGIS二次开发环境的完整搭建流程,从Anaconda配置到解决常见的GDAL/PROJ报错问题。通过虚拟环境管理、PyCharm集成和离线部署策略,帮助开发者高效构建稳定的地理信息系统开发环境,特别适合GIS开发者和Python程序员参考。

weixin_30752699的博客 533

基于STM32的HC-SR04超声波模块测距(新手级)

本人是嵌入式新手,学习了STM32的部分内容,最近想找些项目做,然后顺便学习了一下HC-SR04超声波模块,学习过程中也参考了一些大佬的文章。本文记录了自己的学习方法和学习过程,同时也希望能和各位大佬交流讨论。

weixin_63758495的博客 2206

POJ 2398(计算几何 叉积)

题目链接 题目大意:给你一个被n块挡板分隔成n+1个区域的盒子,给你m个点,从小到大输出含有点的个数的区域有多少个 分析:这题其实和POJ 2318差不多的只是输出不一样,还有每个隔板的读入顺序不一定是从左到右的,所以读入完以后用sort排个序, 这道题其实就是考对叉积的应用,计算矢量叉积是与直线和线段相关的算法的核心部分。 设矢量P = ( x1, y1 ),Q = ( x2, y2 )...

不期而遇 848

从零搭建openEuler ARM64开发测试环境:手把手教你用libvirt+KVM配置虚拟机(含VNC远程安装)

本文详细介绍了如何在ARM64平台上从零搭建openEuler开发测试环境,涵盖libvirt和KVM配置虚拟机的完整流程,包括环境准备、存储配置、网络优化、XML配置详解以及VNC远程安装。特别针对华为欧拉(openEuler)系统进行了优化,帮助开发者快速构建高效的ARM架构虚拟化环境。

weixin_30545945的博客 587

内容审核与文本安全技术综述:检测、过滤与对齐

检测质量高度依赖数据。毒性/仇恨/冒犯语言检测领域形成了一批经典数据集,但它们的标签体系差异很大:例如 OLID(OffensEval)强调“是否冒犯—冒犯类型—目标对象”三层结构;HateXplain 在“hate/offensive/normal”三分类之外,还提供目标群体与人类标注的 rationale span;RealToxicityPrompts 则不做离散标签,而是用毒性分数来研究“模型续写时的毒性退化”。ACL 汇编。

nmdbbzcl的博客 1371

poj2398

/***************************************************************\ *Author:Hu Wenbiao *Created Time: Tue 27 Jul 2010 07:10:34 PM CST *File Name: main.cpp *Description:几何题目。对poj2318的扩展 \***...

weixin_30408165的博客 251

AI工具赋能日常工作的实践指南:以产品经理与程序员为例

AI工具赋能日常工作的实践指南:以产品经理与程序员为例

专注于编程、AI、人工智能等多个领域内容研究和分析 591

poj2398 计算几何

poj2318的升级版,只是中间的n个隔板未排序,输出的是装有i个玩具的区域的个数,其他完全一样 poj2318的解题报告见http://blog.youkuaiyun.com/non_cease/article/details/7754382 #include #include #include #include using namespace std; struct Point {

2210

85-Halcon-- gen_cam_par_area_scan_division 函数功能(生成面阵相机镜头参数)

Halcon的gen_cam_par_area_scan_division算子用于生成面阵相机的镜头参数,支持除法畸变模型。该算子输出包含9个参数的元组,包括焦距(Focus)、畸变系数(Kappa)、像素尺寸(Sx,Sy)、主点坐标(Cx,Cy)和图像尺寸。文中详细解析了各参数含义、数学原理(包括畸变矫正公式和坐标转换),并提供了三个工业应用案例:高精度芯片尺寸测量、机器人焊接引导和大视野汽车表面检测。最后给出了完整的相机标定流程,涵盖参数生成、畸变校正和标定配置步骤,适用于工业视觉系统的精确标定需求。

weixin_45590420的博客 915

Windows配置L2TP/IPsec连接

Windows 系统的 L2TP/IPsec 功能,通过配置即可构建加密 VPN 通道。

m0_61806534的博客 1668

【计算几何】POJ 2398 Toy Storage

POJ 2398 Toy Storage 【传送门】 Toy Storage Time Limit:1000MS Memory Limit:65536K Total Submissions:7764 Accepted:4619 Description Mom and dad have a problem: their child, Reza, ...

lesileqin的博客 229

030、微透镜阵列与光场成像:从光场相机到深度感知的演进

文章摘要: 光场成像通过微透镜阵列(MLA)同时记录光线的位置与方向,实现单次曝光获取三维信息。其核心架构包括主镜头+MLA+传感器或相机阵列,各有分辨率与体积的权衡。光场支持先拍照后对焦和深度估计,但受限于微透镜基线短,精度较低。深度算法需结合多视角立体匹配与极平面图像分析,并处理噪声和温度漂移等实际问题。光场适用于短距离动态场景(如手势识别),而远距离高精度需求仍需激光雷达。建议初学者通过二手光场相机和开源工具入门,理解光场“角度域”与“空间域”的协同机制。

sundong_81的博客 50

poj 2398 Toy Storage(计算几何)

题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子。隔板将这个箱子分成了一些隔间。向其中扔一些玩具,每个玩具有一个坐标,求有\(t​\)个玩具的隔间数(对\(t>0​\)都要输出)。 题目分析:涉及到计算几何的知识是求点在线的哪一侧。可以利用叉积来做。取点\(A\)到隔板的上端点\(B\)的向量\(\vec{AB}...

weixin_30835923的博客 157

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

POJ 2398 Toy Storage [叉积,计算几何]

题目 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9582 Accepted: 5587 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangula

sehnsucht 216

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

POJ 2398- Toy Storage (计算几何入门)

POJ 2398- Toy Storage 还是个比较适合入门的基础题,和POJ 2318相似—>POJ 2318 题解 题目: Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a problem - their child John never put...

weixin_45691686的博客 238

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

poj 2398 Toy Storage (计算几何)

A - Toy Storage Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Mom and dad have a problem: their child, Reza, never puts his toys aw

Ritchie 316

poj2398 Toy Storage 计算几何,叉积,二分

poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2。n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区域,然后分别用0到n表示,m代表玩具的个数,(x1,y1)代表盒子的左上顶点坐标,(x2,y2)代表盒子的右下顶点坐标,接下来的n行,每行都有两个数a,b,(a,y1),(b,y2)分别代...

weixin_30551963的博客 165

ACM-计算几何之Toy Storage——poj2398

ACM 计算几何 Toy Storage poj2398

继续激情,继续奋斗。 2016

(计算几何)POJ2318TOYS、POJ2398Toy Storage

POJ2318TOYS 题意: 给一个矩形和nnn条线将矩形分成n+1n+1n+1块区域,给mmm个点保证点不在线上,问每一块区域里有几个点。 思路: 很容易看出,一个点如果在一个区域内,它会在一条边的顺时针方向和另一条边的逆时针方向。所以用叉积。 如果一个点在一个区域里,设区域为ABCDABCDABCD,点为PPP。可得(AB→×AP→)∗(CD→×CP→)<0(\overrightarrow{AB}\times\overrightarrow{AP})*(\overrightarrow{CD}\ti

Z7784562的博客 193

计算几何 POJ 2398 Toy Storage

Problem Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebel...

FrankDura的博客 526

poj 2398 Toy Storage 【计算几何】【点和线的关系】

计算几何水题

100days 885

POJ 2398 计算几何之Toy Storage

Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious an...

weixin_44705665的博客 141

POJ 2398 Toy Storage(二分+简单计算几何)

Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza ...

苟为蒟蒻又何妨 300

【计算几何】 poj2398 Toy Storage

Toy Storage http://poj.org/problem?id=2398 Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectan

Ted's 游乐园 751

POJ 2398 Toy Storage(计算几何)

题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数。 题解:通过斜率判断一个点是否在两条线段之间。 /** 通过斜率比较点是否在两线段之间 */ #include"iostream" #include"cstdio" #include"algorithm" #include"cstring" using n

Strangedbly 1044
上一篇: POJ - 2318 TOYS————计算几何
下一篇: POJ - 1113 Wall ————计算几何
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值