UVA 1398 - Meteor

《机器学习》周志华_自学记录 第一章绪论## 1.1引言机器学习所研究的主要内容,是关于在计算机上从数据中产生"模型"(model)的算法,即"学习算法"(learning algorithm).在面对新的情况时(例如看到一个没剖开的西瓜),模型会给我们提供相应的判断(例如好瓜).如果说计算机科学是研究关于"算法"的学问,那么类似的,可以说机器学习是研究关于"学习算法"的学问.## 1.2基本术语:用于预测离散值,例如将样本分为“好瓜”或“坏瓜”。:用于预测连续值,例如西瓜的成熟度(如0.95、0.37)。 阅读详情

 The famous Korean internet company nhn has provided an internet-based photo service which allows The famous Korean internet company users to directly take a photo of an astronomical phenomenon in space by controlling a high-performance telescope owned by nhn. A few days later, a meteoric shower, known as the biggest one in this century, is expected. nhn has announced a photo competition which awards the user who takes a photo containing as many meteors as possible by using the photo service. For this competition, nhn provides the information on the trajectories of the meteors at their web page in advance. The best way to win is to compute the moment (the time) at which the telescope can catch the maximum number of meteors.

You have n meteors, each moving in uniform linear motion; the meteor mi moves along the trajectory pi + t×vi over time t , where t is a non-negative real value, pi is the starting point of mi and vi is the velocity of mi . The point pi = (xi, yi) is represented by X -coordinate xi and Y -coordinate yi in the (X, Y) -plane, and the velocity vi = (ai, bi) is a non-zero vector with two components ai and bi in the (X, Y) -plane. For example, if pi = (1, 3) and vi = (-2, 5) , then the meteor mi will be at the position (0, 5.5) at time t = 0.5 because pi + t×vi = (1, 3) + 0.5×(-2, 5) = (0, 5.5) . The telescope has a rectangular frame with the lower-left corner (0, 0) and the upper-right corner (w, h) . Refer to Figure 1. A meteor is said to be in the telescope frame if the meteor is in the interior of the frame (not on the boundary of the frame). For exam! ple, in Figure 1, p2, p3, p4 , and p5 cannot be taken by the telescope at any time because they do not pass the interior of the frame at all. You need to compute a time at which the number of meteors in the frame of the telescope is maximized, and then output the maximum number of meteors.

\epsfbox{p3905.eps}

Input 

Your program is to read the input from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case starts with a line containing two integers w and h (1$ \le$w, h$ \le$100, 000) , the width and height of the telescope frame, which are separated by single space. The second line contains an integer n , the number of input points (meteors), 1$ \le$n$ \le$100, 000 . Each of the next n lines contain four integers xi, yi, ai , and bi ; (xi, yi) is the starting point pi and (ai, bi) is the nonzero velocity vector vi of the i -th meteor; xi and yi are integer values between -200,000 and 200,000, and ai and bi are integer values between -10 and 10. Note that at least one of ai and bi is not zero. These four values are separated by single spaces. We assume that all starting points pi are distinct.

Output 

Your program is to write to standard output. Print the maximum number of meteors which can be in the telescope frame at some moment.

Sample Input 

2 
4 2 
2 
-1 1 1 -1 
5 2 -1 -1 
13 6 
7 
3 -2 1 3 
6 9 -2 -1 
8 0 -1 -1 
7 6 10 0 
11 -2 2 1 
-2 4 6 -1 
3 2 -5 -1

Sample Output 

1 
2


有n个流星,各自以不同速度朝不同方向运动,求所有时刻,同时在矩形区域中的最大流星数,边界上的不算。


所有流星,能求出进入矩形和离开矩形区域的时间。这个时间段可以在数轴上表示出来,只要求出数轴上的点被不同时间段重叠次数最大的值即可。

从左往右扫描,遇到时间起点计数++,遇到时间终点计数--,维护此过程中的最大计数。

注意这里有一个问题,对于终点和起点重合的时间点t,先--后++,因为t时刻计算完的计数值,实际上是刚过t的时刻在矩阵中的流星数。终点的应当减去,起点的加上,如果先加后减,则把将要离开的流星也算上了,会导致max值更新,导致错误答案。


对于除法,若只需计算后的相对大小关系,为提高精度避免浮点运算,可以将被除数乘以所有除数的最小公倍数(应在整数范围内)。

 

#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int MAX = 100000 + 5;
const int MAX_T = 1000000000 + 5;

struct point
{
    int t,type;//t = -1 表示是下界 1表示上界 
    
    bool operator <(const point& p)const
    {
        return t < p.t || (t == p.t && type > p.type);//某一时间点在边界上的 不算 x实际 
    }
}p[MAX * 2];
 

int x,y,a,b,min_t,max_t; 

void caculate_t(int edg, int pos,int v)
{
    if(v == 0)
    {
        if(pos <= 0 || pos >= edg)max_t = -1;//注意 边界不能算 
        return;
    } 
    
    int t1 = max(0, -2520 / v * pos);
    int t2 = max(0, 2520 / v * (edg - pos));
    //printf("pos :%d  edg:%d v:%d t1:%d  t2:%d\n",pos,edg,v,t1,t2);
    min_t = max(min_t, min(t1, t2));
    max_t = min(max_t, max(t1, t2)); 
    
    //printf("pos :%d  edg:%d v:%d l:%d  r:%d======\n",pos,edg,v,min_t,max_t);
}

void get_result(int n)
{
     int m = 0,cnt = 0;
     for(int i = 0; i < n; i++)
     {
         if(p[i].type < 0)m = max(++cnt, m);
         else cnt--;
         
        
     }
     printf("%d\n",m);
}

int main(int argc, char *argv[])
{
    
    int t,w,h,n;
    
    
    scanf("%d",&t);
    
    while(t--)
    {
        scanf("%d%d%d",&w,&h,&n);
        int cnt = 0;
        for(int i = 0; i < n; i++)
        {
            scanf("%d%d%d%d",&x,&y,&a,&b);
        
            min_t = 0; max_t = MAX_T;
            caculate_t(w, x, a);
            caculate_t(h, y, b);
        
            if(max_t > 0 && max_t > min_t)
            {
                p[cnt++] = (point){min_t, -1};
                p[cnt++] = (point){max_t, 1};
            }
        }
        
        sort(p, p + cnt);
        get_result(cnt);
        
        
        
    }
    
    //system("PAUSE");
    return EXIT_SUCCESS;
}





星空组网 vs 蒲公英 vs Tailscale:2024年国内免费异地组网工具横评(含实测数据) 本文对2024年国内主流免费异地组网工具星空组网、蒲公英和Tailscale进行了深度横向评测。基于实测数据,重点分析了三者在P2P成功率、中继延迟、传输速度及稳定性方面的表现,为中小企业、远程办公及个人开发者提供了清晰的选择指南。星空组网在国内网络环境下展现出优秀的平衡性。 阅读详情

相关推荐

从零构建:Trinamic API在STM32上的深度移植与TMC-IDE通信实战

本文详细介绍了如何从零开始在STM32平台上深度移植Trinamic API,并实现与TMC-IDE工具的稳定通信。内容涵盖SPI底层驱动定制、寄存器配置、高级功能实现及调试技巧,重点解析了TMC5160芯片的集成实践,帮助开发者构建可靠的嵌入式运动控制系统。

w1x2y3的博客 254

UVA1398 Meteor(几何+扫描线)

UVA1398 Meteor 扫描线的裸题,但是其中的几何知识倒是挺有意思,就是判断一个射线进入目标矩阵的进入时间和离开的时间: 假设源点的位置是(x,y),移动的速度是(a,b),矩阵的左下角是(0,0),右上角是(w,h) 一:最朴素的思路: 由几何知识可知,这条射线过(x+at,y+bt),首先有几种情况是可以排除的: 1、a>0 && x>w 2、a<0 && x<0 3、b>0 && y>h 4、b<0 &a

daq0411的博客 189

Matlab实战:用卡尔曼滤波搞定无人机GPS轨迹优化(附完整代码)

本文详细介绍了如何使用Matlab实现卡尔曼滤波(KF)算法优化无人机GPS轨迹,提供完整代码和工程实践指南。通过线性卡尔曼滤波技术,有效降低定位噪声,提升轨迹平滑度,适用于无人机导航和控制系统开发。

weixin_29061425的博客 253

uva 1398 - Meteor(贪心)

题目链接:uva 1398 - Meteor 题目大意:给出一个w和h,表示说照相机可以照到的范围,然后有n个彗星,给出起始坐标以及移动的向量,问说一张照片最多有几个彗星。 解题思路:根据坐标和移动向量求出进入范围和离开范围的时间,按照时间进行排序,然后没进一次加1,出一个减1,维护最大值,注意有可能存在彗星不进入范围。 #include &lt;stdio.h&gt; #i...

xiaoheliushuiya 134

【实战】——零代码玩转Supervisely人像分割:从标注到模型训练的数据流水线搭建

本文详细介绍了如何零代码使用Supervisely平台搭建人像分割数据流水线,从智能标注到数据集格式转换,再到模型训练与优化。Supervisely的智能标注工具和协作功能大幅提升了人像分割项目的效率,特别适合视频会议背景虚化、虚拟试衣等应用场景。

weixin_30694389的博客 416

uCOS中的消息邮箱(:task与task之间传递一个数据(数据缓冲区))

程序需求,需要完成task与task之间  字符数组的数据传输 比如:在ucos中,串口2接收的字符数组是不定时的&不定长的;只有当接收到数据的时候_才将数据赋值给新数组 具体的程序示意如下: 图1:消息邮箱测试中的     向消息邮箱发送消息(OSMboxPost(Str_Box,(void*)rec);//发送消息--(向 消息邮箱_msg_key发送消息) ),实际项目需求的

faguoduifangui的博客 4540

Meteor UVA - 1398(一道挺经典的题目,关于区间的操作)

Meteor UVA - 1398 题意: 给你一个矩形框框。有n个点,它们有起始位置(x,y),速度(a,b)。 问: 是否存在一个时刻,有几个点在一个矩形框框里。求最大值。 思路(简化): 先简化下问题,首先可以考虑,那么假如有多个开区间, 现在要你求:找到一个点,使得这个点被最多的开区间覆盖。 那么可以把区间的左右端点抽象成事件。 按照时间的先后排序。 假如有两个事件的发生时间一样,那么右端点优先(因为是开区间) 之后遍历事件,当遇到一个左端点时,cnt++;当遇到一个右端点时cnt–。 ans=

qq_45377553的博客 195

SAP FICO 中的 F-02 :概念、使用场景及案例解析

在 SAP FICO (财务会计与管理会计) 模块中,F-02 是一个用于录入总账凭证的事务代码。这个事务代码主要用于手动输入总账凭证,适用于各类财务交易,例如资产购入、费用支付、收入确认等。F-02 的重要性在于,它允许财务人员在 SAP 系统中创建凭证,并确保这些凭证能够正确影响总账账户。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2062

UVA1398 Meteor

在tusha Meteor Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Submit]   [Go Back]   [Status]   Description The famous Korean inter

610

AI训练师三级考证避坑指南|假证辨别+机构套路+OSTA验证

这是最基础的问题,也是最容易忽略的问题。人工智能训练师三级证书本身是有价值的——政府认可的职业技能等级证书、多地紧缺工种补贴、人才引进加分。但正因为有价值,才引来了大量骗子。记住三句话OSTA查不到的证,一分钱都不值声称免考包过的,100%是骗子培训费一次性谈清楚,后续加价直接走人如果你正在考虑考人工智能训练师三级证书,想要从报名到备考到拿证的完整一站式指南,欢迎查看我的付费专栏:📖《人工智能训练师三级·从零到拿证完全指南》99篇系统化内容,覆盖报名、备考、冲刺、拿证全流程。

白话机器学习 1222

UVa 1398 Meteor

本文提出了计算望远镜框架内流星数量峰值时刻的算法。给定n颗匀速直线运动的流星,每颗流星的轨迹由起点和速度向量确定。通过计算每颗流星进入和离开矩形框架的时间区间,并利用扫描线算法处理这些时间事件,可以高效地找到框架内流星数量最多的时间点。算法通过处理X和Y方向的时间区间交集,并优先处理离开事件来保证精度,最终输出最大流星数。该方法适用于大规模数据输入,时间复杂度为O(n log n)。

寂静山林 740

QGis软件 —— 1、Windows10下载安装QGis及插件

QGis —— 1、Windows10下载安装QGis及插件

5160

uva 1398 Meteor

https://vjudge.net/problem/UVA-1398 !!!:uvalive炸了,简直有毒,标程提交都有错。 题意: 一个矩形的相机,左下坐标是(0,0),右上坐标是(w,h),在这个坐标系内,有许多正在飞的流星,每个流星用两个向量表示,一个表示初始位置,另一个表示速度向量,问照相机范围内星星最多的时候有多少颗。 在相机边界的点是不在相机范围内的。(即为开区间。) 思路...

weixin_30391339的博客 143

温度PID控制PLC程序

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

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

uva 1398 - Meteor

点击打开链接uva 1398 思路:扫描法 分析: 1 不难发现,流星的轨迹是没有用的,有意义的只是每个流星在照相机视野内出现的时间段 2 那么我们就可以通过去求出没个流星在矩形内的时间段,然后利用扫描法去求。 具体见刘汝佳&lt;&lt;训练指南46页&gt;&gt; 代码: #include&lt;cstdio&gt; #include&lt;cstring&gt; #in...

我是传奇 214

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

uva1398 - Meteor

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=460&problem=4144&mosmsg=Submission+received+with+ID+12204651 题目大意:给定那个流星的初始位置,和向量速度v(1,2),表示每秒x轴移动

yxr941225的专栏 608

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Uva1398 Meteor

扫描线法。 将流星出现在相机里的时间转化成线段,离散化端点后,扫描何时出现的流星最多。注意边界的不算,所以要先减右端点再加左端点 1 /*By SilverN*/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstr...

dezhen7015的博客 121

【ICPC-173】uva 1398 - Meteor

点击打开链接uva 1398 思路:扫描法 分析: 1 不难发现,流星的轨迹是没有用的,有意义的只是每个流星在照相机视野内出现的时间段 2 那么我们就可以通过去求出没个流星在矩形内的时间段,然后利用扫描法去求。 具体见刘汝佳<<训练指南46页>> 代码: #include<cstdio> #include<cstring> #inclu...

藏经阁 | 玄苦 1142

uva 1398 - Meteor

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=460&page=show_problem&problem=4144 先存代码,睡觉去了  代码: #include #include #include #include us

D_Double's Journey 1521
上一篇: UVA 11549 Calculator Conundrum
下一篇: Uva 1121 Subsequence
CSLDBLYDX
博客等级 码龄16年 3粉丝 99原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值