POJ2398 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 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;
}


内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与运动模拟展开,重研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据技术支持。; 适合人群:具备一定自动控制理论基础Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值