D - Meteor

LA 3905

题意:有一个照相机相框,只有在相框内的点才可以被拍到,每一个点都有起始位置(x,y)和速度(a,b),问这个相框最多可以拍摄到多少个点

思路:拍摄肯定是一个瞬时性的动作,那么最终拍摄到点的多少肯定与时间的选取有关,因此可以吧所有的点在相框内出现的时间转化为一个区间。

最后进行遍历,遇到左区间加一,遇到右区间减一

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn=1e5+10;
struct node
{
    double x;
    int type;
    bool operator < (const node & a) const
    {
        if(x!=a.x)
            return x<a.x;
        return  type>a.type;           //如果位置相同,肯定右区间在前,因为在相机边界上的点不会被照到
    }
}event[maxn*2];

void update(int x,int a,int w,double &l,double &r)
{
    if(a==0)
    {
        if(x<=0||x>=w) r=l-1;
    }
    else
    {
        if(a>0)
        {
            l=max(l,-(double)x/a);
            r=min(r,(double)(w-x)/a);
        }
        else
        {
            l=max(l,(double)(w-x)/a);
            r=min(r,-(double)x/a);
        }
    }
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
     int n,w,h,x,y,a,b,e=0;
     scanf("%d%d%d",&w,&h,&n);
     for(int i=0;i<n;i++)
     {
         scanf("%d%d%d%d",&x,&y,&a,&b);
         double l=0,r=1e9;
         update(x,a,w,l,r);
         update(y,b,h,l,r);
         if(l<r)
         {
             event[e++]=(node) {l,0};
             event[e++]=(node) {r,1};
         }
     }
         sort(event,event+e);
         int ans=0;
         int cnt=0;
         for(int i=0;i<e;i++)
         {
             if(event[i].type==0) ans=max(ans,++cnt);
             else                 cnt--;
         }
         printf("%d\n",ans);
     }
    return 0;
}

时间: 2024-08-25 11:53:21

D - Meteor的相关文章

oracle/node-oracledb 数据库驱动 与 Meteor 驱动包!

oracle/node-oracledb: https://github.com/oracle/node-oracledb   Oracle 官方维护. metstrike/meteor-oracle: https://github.com/metstrike/meteor-oracle Oracle Database Driver for Meteor. Translates the meteor collection operations into SQL. Detailed install

Meteor:组件思想

受React组件思想启发,本文讨论在Meteor客户端应用组件化思想,以Spacebar模板语言为例. 所谓前端组件(我的定义),是一组html代码以及相关样式.行为的封装.它可被复用,通过传递参数进行初始化,并可以调用其定义的方法对其进行控制.并且,其状态,样式都是局部封装的,不会扩散并影响全局. 典型地,一个组件具有data和states(React中叫做props和statues).data是外部传入,用于构建.渲染组件的数据,在组件实例的整个生命周期中是不变的.states是组件内部封装

Meteor 中的代码包有点特殊,分为五种

Meteor 中的代码包有点特殊,分为五种: Meteor 核心代码本身分成多个核心代码包(core package),每个 Meteor 应用中都包含,你基本上不需要花费精力来维护它们 常规 Meteor 代码包称为"isopack",或同构代码包(isomorphic package,意味着它们既能在客户端也能在服务器端工作).第一类代码包例如 accounts-ui 或 appcache 由 Meteor 核心团队维护,与 Meteor 捆绑在一起. 第三方代码包就是其他用户开发

为什么我要放弃meteor

最近接了一个老外的项目,对方要求用meteor开发.刚开始我觉得这个框架太好了,甚至打算以后在自己项目中也用这个框架,经过这段时间的使用,我今天来谈谈自己对这个框架的理解.meteor是一个基于nodejs平台的实时web开发框架,采用全新的编程理念,全新的通信模式.具体情况,可以百度,这里就不废话了. 先来说说优点: 1. 搭建环境非常简单,可以轻松建立开发环境,文档还算齐全. 2. 前后端语言统一,前后端完全整合,后端与前端完全可以共享代码,比如,定义在一个文件中的常量,函数,在后端可以调用

洛谷 P2895 [USACO08FEB]流星雨Meteor Shower

P2895 [USACO08FEB]流星雨Meteor Shower 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her safety, she vows to find her way to a safe locatio

POJ 3669 Meteor Shower 题解 《挑战程序设计竞赛》

题目链接: http://poj.org/problem?id=3669 题意: 这个同学发现流星雨要来了,会对地球造成伤害于是决定逃跑.N颗流星会不定时降落在坐标轴第一象限300*300内的点上.给出每颗流星降落的坐标和时刻,求这个同学能否成功逃跑,能的话用时多少. 思路: 略有一点tricky,无法变通了(@﹏@)~.看了码农场的代码. 这道题没有给出地图,所以需要自己生成地图. 关键的点在于:在生成地图的时候,将每个点的初始值设为无穷大(表示不会有流星),将要被摧毁的点设置为流星降落的时刻

meteor实例—7—发布(Publication)和订阅(Subscription)

发布(Publication)和订阅(Subscription)是 Meteor 的最基本最重要的概念之一,但是如果你是刚刚开始接触 Meteor 的话,也是有些难度的.这已经导致不少误解,比如认为 Meteor 是不安全的,或者说 Meteor 应用无法处理大量数据等等.人们起初会感觉这些概念很迷惑很大程度上是因为 Meteor 像变魔法一样替你做了很多事儿.尽管这些魔法最终看起来很有效,但是它们掩盖了后台真正做的工作(好像魔术一样).所以让我们剥去魔法的外衣来看看究竟发生了什么.过去的日子首

[题解]poj Meteor Shower

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16313   Accepted: 4291 Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious fo

poj3669 Meteor Shower(BFS)

题目链接:poj3669 Meteor Shower 我只想说这题WA了后去看讨论才发现的坑点,除了要注意原点外,流星范围题目给的是[0,300],到302的位置就绝对安全了... 1 #include<cstdio> 2 #include<cmath> 3 #include<queue> 4 #include<cstring> 5 #include<algorithm> 6 #define CLR(a,b) memset((a),(b),siz

Using View and Data API with Meteor

By Daniel Du I have been studying Meteor these days, and find that Meteor is really a mind-blowing framework, I can talk about this latter. I was inspired by this question on forum and started to looking at the possibilities of using View and Data AP