POJ2398 Toy Storage 判断点和线的关系+二分+计数

LabVIEW vs Python:谁更适合你的ATE自动化测试系统?实测对比与选型建议 本文深入对比了LabVIEW和Python在ATE自动化测试系统中的性能表现、开发效率和应用场景,帮助工程师根据实时控制需求、数据处理复杂度及团队技能做出最优选型决策。通过实测数据和典型案例,分析两者在硬件集成、系统性能和维护成本等方面的差异,并提供混合架构实施建议。 阅读详情

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 <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
#define INF 0x3f3f3f3f
#define CVector CPoint
typedef long long LL;
double PI=acos(-1);
double ESP=1e-6;
struct CPoint{
    double x,y;
    CPoint(double xx,double yy):x(xx),y(yy){}
    CPoint(){}
};
struct CLine{
    CPoint a,b;
    CLine(CPoint aa,CPoint bb):a(aa),b(bb){}
    CLine(){}
};
CPoint operator +(CPoint a,CPoint b){
    return CPoint(a.x+b.x,a.y+b.y);
}//c=a+b
CPoint operator -(CPoint a,CPoint b){
    return CPoint(a.x-b.x,a.y-b.y);
}//c=a-b
CPoint operator *(CPoint a,double k){
    return CPoint(k*a.x,k*a.y);
}//c=k*a;
CPoint operator *(double k,CPoint a){
    return CPoint(k*a.x,k*a.y);
}//c=k*a
double operator *(CPoint a,CPoint b){
    return a.x*b.x+a.y*b.y;
}//c=a*b 点击
double operator ^(CPoint a,CPoint b){
    return a.x*b.y-a.y*b.x;
}//叉积
double Length(CVector p){
    return sqrt(p*p);
}//求长度
CVector unit(CVector p){
    return 1.0/Length(p)*p;
}//求p方向单位向量
double project(CVector p,CVector n){
    return p*(unit(n));
}//求p在n方向上投影长度
double area(CVector a,CVector b){
    return a^b*0.5;
}//求a,b所夹的有向面积
bool isZero(double x){
    return -ESP<x&&x<ESP;
}//判断是否为0
double dist(CPoint p,CPoint q){
    return Length(p-q);
}//求两点间距离
double dist(CPoint p,CLine l){
    return fabs((p-l.a)^(p-l.b))/Length(l.a-l.b);
}//求点到线的距离
CPoint Rotate(CPoint a,CPoint b,double alpha){
    CVector p=b-a;
    return CPoint(a.x+(p.x*cos(alpha)
                       -p.y*sin(alpha)),
                  a.y+(p.x*sin(alpha)
                       +p.y*cos(alpha)));
}//b绕a逆时针旋转alpha
int sideOfLine(CPoint p,CLine l){
    double res=(p-l.a)^(p-l.b);
    if(isZero(res)){
        return 0;
    }else{
        return res>0? 1:-1;
    }
}//判断点和直线关系,0-直线上,1-左,-1-右
CLine Vertical(CPoint p,CLine l){
    return CLine(p,p+(Rotate(l.b,l.a,PI/2)-l.a));
}//求过p的l的垂线
CPoint root(CPoint p,CLine l){
    return l.a+project(p-l.a,l.b-l.a)*unit(l.b-l.a);
}//垂足
double angle(CLine l,CLine m){
    return acos(fabs(
                project(l.b-l.a,m.b-m.a)
                /Length(l.b-l.a)));
}//两直线夹角
CLine s[1005];
int num[1005],cnt[1005];
bool cmp(CLine a,CLine b){
    return a.a.x<b.a.x&&a.b.x<b.b.x;
}
int main()
{
    int n,m;
    double x1,x2,y1,y2;
    while(~scanf("%d",&n),n){
        int maxn=0;
        scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2);
        memset(num,0,sizeof(num));
        memset(cnt,0,sizeof(cnt));
        s[0].a=CPoint(x1,y1);
        s[0].b=CPoint(x1,y2);
        for(int i=1;i<=n;i++){
            double x_1,x_2;
            scanf("%lf%lf",&x_1,&x_2);
            s[i].a=CPoint(x_1,y1);
            s[i].b=CPoint(x_2,y2);
        }
        sort(s+1,s+1+n,cmp);
        s[n+1].a=CPoint(x2,y1);
        s[n+1].b=CPoint(x2,y2);
        while(m--){
            double x,y;
            scanf("%lf%lf",&x,&y);
            CPoint temp(x,y);
            int l=0,r=n+1;
            int _m=(l+r)/2;
            while(r-l>1){
                if(sideOfLine(temp,s[_m])==-1){
                    r=_m;
                }else{
                    l=_m;
                }
                _m=(l+r)/2;
            }
            if(num[_m]){
                cnt[num[_m]]--;
            }
            num[_m]++;
            cnt[num[_m]]++;
            maxn=max(maxn,num[_m]);
        }
        printf("Box\n");
        for(int i=1;i<=maxn;i++){
            if(cnt[i]){
                printf("%d: %d\n",i,cnt[i]);
            }
        }
    }
    return 0;
}


newman的使用 Newman是一个基于Node.js的postman命令行工具,用于运行和测试PostmanAPI 请求的集合。它允许用户在命令行环境中执行Postman的JSON文件,从而实现接口自动化测试和持续集成,同时支持用户进行自动化测试、批量执行请求、生成报告等操作。 阅读详情

相关推荐

模拟IC实战:从零构建放大器并完成零极点仿真分析

本文提供了一份模拟IC设计实战指南,手把手教你从零开始,在Cadence Virtuoso中搭建一个单级共源放大器。通过详细的原理图绘制、直流工作点检查,并重点完成了零极点仿真分析,直观展示了电路频率响应与参数调整的关系,帮助初学者快速建立动手实践能力与电路直觉。

github5actions的博客 492

poj 2398 Toy Storage

Toy Storage Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u [Submit]   [Go

codeStone 901

【提示学习代码】CoOp代码详读

CoOp是对CLIP的改进工作,主要是对prompt进行学习从而不用来手动设置prompt。自定义CLIP模型:上述两个模块结合而成的CLIP。文本编码器,接收文本的输入,并输出相应的编码表示。将图像和文本进行编码并计算它们之间的相似性。permute后变成了(4,2,3)Prompt学习器,用于学习生成提示。

weixin_51293984的博客 5823

Toy Storage[向量叉积 + 排序 + 二分]

Toy Storage 计算几何基础题 题意大致是:一个长方格,被分成好几个空间,然后再给你一堆点,问你每个空间里面有多少个点。 脑洞:题意里面说了,这些分割空间的线没有交点,我们把他们用两个数组存一下,排个序。 如何判断点是在哪个格子呢? 将这个点和分割线的两端连线,形成两个向量(注意向量的方向,为该点指向分割线的两端), 如果这两个向量的叉积为负数(注意叉乘时两个向量的前后位置),则说明左...

rain_island的博客 228

Verilog--CDC跨时钟域处理(快时钟域到慢时钟域)

Verilog--CDC跨时钟域处理(快时钟域到慢时钟域)CDC问题单比特信号的跨时钟域问题从快时钟域到慢时钟域从慢时钟域到快时钟域多比特信号的跨时钟域问题异步FIFO握手协议 今天先写单比特信号从快时钟域到慢时钟域的方法,后续继续填坑 CDC问题 单比特信号的跨时钟域问题 从快时钟域到慢时钟域 设计思想   从慢时钟域到快时钟域通常使用打两拍的方法,这也适用于从快时钟域到慢时钟域时,但是如果当单比特信号持续时间小于快时钟域的一个周期时,需要用展宽信号再打两拍的方法。 设计相关代码 module Sync_

weixin_44425619的博客 9378

Adobe软件非正版弹窗终极解决方案:PS/Ai/PR/AE禁用提示一键清除指南

本文提供了Adobe软件非正版弹窗的终极解决方案,包括PS、Ai、PR、AE等软件的禁用提示一键清除指南。通过专业清理工具和手动修改系统文件的方法,帮助用户彻底解决Adobe弹窗问题,提升使用体验。适用于Windows和Mac系统用户,操作简单高效。

weixin_30872337的博客 8548

POJ2318 TOYS 和POJ2398 Toy Storage题解(点在四边形内)(简单几何)

POJ 2318 TOYS 链接:http://poj.org/problem?id=2318 POJ 2398 Toy Storage 链接:http://poj.org/problem?id=2398 poj2318题目大意:给你一个盒子的俯视图,从左到右将每个格子划分为0,1,2...n;给你一些点的坐标,让你输出每个格子里点的个数。 poj2398题目大意:给你一个盒子的俯视

若世界是黑暗,那我便是黎明。 弱者为何而战!? 540

强化学习-----DQN(Deep Q-network)

DQN(Deep Q-Network)是一种基于深度学习和强化学习的算法,由DeepMind提出,用于解决离散动作空间下的马尔科夫决策过程(MDP)问题。它是首个成功将深度学习应用于解决强化学习任务的算法之一。DQN,即深度Q网络(Deep Q-network),是指基于深度学习的Q-Learing算法。那什么是Q-leaning?可以看上一篇文章Q-learning是一种经典的强化学习算法,用于解决马尔可夫决策过程(Markov Decision Process,MDP)中的控制问题。

qq_74722169的博客 2万+

POJ 2318 TOYS && POJ 2398 Toy Storage [判断点在四边形中]

题目链接:http://poj.org/problem?id=2318

927

VFIO框架源码分析(二十一)- IOMMUFD 模式下的 DMA 映射机制

在虚拟化 I/O 的世界里,无论上层管理面(如对象模型、设备绑定)如何重构,数据面最核心的任务始终未变——DMA 映射(DMA Mapping)。即如何建立 Guest Physical Address (GPA) 到 Host Physical Address (HPA) 的映射关系,并将其填入 IOMMU 的硬件页表中,使得直通设备能够正确访问虚拟机内存。在 Legacy VFIO (Type1) 时代,这一职责由承担,它通过ioctl 操作 Container。

qq_36071928的博客 1028

手把手教你学Simulink——基于重复控制(RC)的并网逆变器场景实例:基于RC的单相并网逆变器仿真

本次教程深入剖析了重复控制(RC)在单相并网逆变器中的应用,解决了周期性谐波抑制这一核心难题。核心收获RC是谐波抑制的“核武器”:它利用内模原理,对所有周期性谐波提供无限大增益,实现理论上无静差的跟踪和抑制。PI+RC是黄金组合:PI提供快速响应,RC提供稳态精度,二者结合,兼顾了动态与稳态性能。结构简单,效果卓越:相比多个PR控制器,RC仅需一个模块,即可抑制所有谐波,设计简洁。电能质量的终极追求,是波形的纯净。重复控制,如同一位不知疲倦的校对员它记住每一次错误(上一周期的误差),

MHD0815的博客 195

poj 2318 TOYS & poj 2398 Toy Storage (叉积)

链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段。而且这些线段坐标是依照顺序给出的。 有n条线段,把盒子分层了n+1个区域,然后有m个玩具。这m个玩具的坐标是已知的,问最后每一个区域有多少个玩具 分析:从左往右。直到推断玩具是否在线段的逆时针方向为止。这个就须要...

aoe41606的博客 134

ESP32学习笔记06-UART 的485 通讯模式

通信方式选择UART 控制器支持多种通信模式,使用函数 uart_set_mode() 可以选择模式。选择特定模式后,UART 驱动程序将处理已连接 UART 设备的相应行为。例如,主机开始向 Tx FIFO 缓冲区写入数据时,UART 驱动程序会自动置位 RTS 管脚(逻辑 1);最后一位数据传输完成后,驱动程序就会取消置位 RTS 管脚(逻辑 0)。要使用此模式,软件。

Car12 2485

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 rebellio...

Happig的博客 171

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

poj 2398 Toy Storage 【二分】

点击打开链接 题意 :             给你个箱子,然后n个隔板把箱子分成 n+1各区域。             然后给你最后玩具的具体位置坐标。而且保证玩具不会在隔板上也不会在箱子外面。             个上一题的区别是这次问你放了多少个玩具的区间分别是多少个。 题解:        

zoro_n的博客 312

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 2398 Toy Storage

题意: 给你一些玩具,找出有t个玩具的区间个数。 题解: poj2318的简单进阶,区别:隔断无序,需要对这些分段进行排序。然后哈希存具有t个玩具的区间。 代码: #include <stdio.h> #include <cstring> #include <cmath> #include <iostream> #in...

167

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

poj2398 Toy Storage【叉乘】

题目链接:http://poj.org/problem?id=2398 题意:题意和poj 2318惊人的相似,只不过输出有点不一样,输出是指有多少个盒子含有那么多个玩具,比如样例一,含有两个玩具的盒子有两个。还有就是给出的挡板是没有排好序的 解析:把挡板排好序以后,就用叉乘判断玩具的位置即可,输出的时候稍微处理一下就好#include <cmath> #include <algorithm>

22h's Blog 423

POJ 2398 Toy Storage (判断点与直线关系+排序二分计数)

Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4851   Accepted: 2878 Description Mom and dad have a problem: their child, Reza, never puts his toy

滴水穿石,慢慢积累,总会有成果 346

poj 2398 Toy Storage

题意:和POJ 2318一样,只是中间的n个隔板未排序,输出的是装有i个玩具区域的个数。 POJ 2318:http://blog.csdn.net/veritaswu/article/details/48714237 #include"iostream" #include"cmath" #include"cstring" #include"cstdlib" using namespace

veritaswu的专栏 386

POJ 2398 Toy Storage(判定点在四边形内)

POJ 2398 Toy Storage(判定点在四边形内) http://poj.org/problem?id=2398 题意:        有一个平行于坐标轴的长矩形,被n块木板分成了n+1个包间.然后给你一些点的坐标,要你从小到大输出t:x. 其中t:x表示包含t个点的隔间有x个.t按从小到大排序. 分析:        本题与POJ2318基本一样, http://blog.

code 801

Toy Storage POJ - 2398

题意:给你盒子的分割点的左上角与右下角,给你点询问在区域内有多少个点 /* *          ┏┓     ┏┓ *         ┏┛┗━━━━━┛┗ *         ┃        ┃   *         ┃   ━    ┃ *         ┃ >   <  ┃ *         ┃        ┃ *         ┃....

Ray.C.L的博客 160

poj 2398 Toy Storage(计算几何:叉积)

基本上和poj 2318一模一样。。。 改下输出就可以了 代码如下: /* *********************************************** Author :yinhua Created Time :2014年12月01日 星期一 19时25分15秒 File Name :poj2398.cpp *********************

小华在努力~ 522

POJ 2398 Toy Storage

Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3024   Accepted: 1726 Description Mom and dad have a problem: their child, Reza, never puts his toy...

weixin_33889245的博客 86

POJ 2398 Toy Storage(点与直线关系 + 二分)

题目链接:http://poj.org/problem?id=2398 这个题目和上一篇博客题目意思几乎一样,不过这个是要求格子内装玩具个数为i的格子数 具体解法基本一致! #include #include #include #include #include using namespace std; #define maxn 6000 struct point{ d

sunrain的专栏 920

POJ 2318 TOYS && POJ 2398 Toy Storage

读懂题是关键。                                 POJ2318 TOYS   原题地址:http://poj.org/problem?id=2318 题目大意:有一个大箱子,由n个板分为n+1块,标号为0~n已知盒子左上角和右下角的坐标及每个板上下两端的横坐标(板不会交错,且按顺序给出)然后给出玩具的坐标,统计每块空间内玩具个数(保证玩具一

王老大 419

POJ 2398 Toy Storage sort+叉积+二分

http://poj.org/problem?id=2398 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. Unfor...

xiji333的博客 201
上一篇: CodeFroces723D Lakes in Berland BFS
下一篇: UVALive5964 LCM Extreme && UVA11426 GCD - Extreme (II) 欧拉函数筛法
Megumin
博客等级 码龄10年 3粉丝 89原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址