uva 1398 - Meteor 模拟 99

简介:

   最近多练练简单题,简单的扫描线

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int w,h,n;
const int inf=1e9;
struct point
{
    point(){};
    point(int x,int y):time(x),type(y){};
    int time;
    int type; //1为开始,-1为结束
    bool operator <(const point &a) const
    {
        return time<a.time||(a.time==time&&type<a.type);
    }
};
point org[200005];
int update(int w,int b,int a,int &L,int &R)
{
    if(a==0)
    {
        if(b<=0||b>=w)R=L-1;
    }
    else if(a>0)
    {
        L=max(L,-2520*b/a);
        R=min(R,2520*(w-b)/a);
    }
    else
    {
        L=max(L,2520*(w-b)/a);
        R=min(R,-2520*b/a);
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int cnt=0;
        scanf("%d%d%d",&w,&h,&n);
        int x,y,vx,vy;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&x,&y,&vx,&vy);
            int l=0,r=inf;
            update(w,x,vx,l,r);
            update(h,y,vy,l,r);
            if(l<r)
            {
                org[cnt++]=point(l,1);
                org[cnt++]=point(r,-1);
            }
        }
        sort(org,org+cnt);
        int ans=0,t=0;
        for(int i=0;i<cnt;i++)
        {
            t+=org[i].type;
            ans=max(ans,t);
        }
        printf("%d\n",ans);
    }
}



目录
相关文章
|
4月前
|
程序员 C++ 计算机视觉
|
8月前
uva127 "Accordian" Patience
uva127 "Accordian" Patience
24 0
|
C#
Silverlight 游戏开发小技巧:技能冷却效果2(Cool“.NET研究”down)2
  可能会奇怪为什么有来一个第2号版本,其实,这是改进版本,而这个改进版本实现起来更加容易,更加方便,但是问题也是很明显的,因为会加上一个上海徐汇企业网站设计与制作100多KB的DLL,对于网页游戏来说,任何1KB都是宝贵的资源,就为了这个小效果而平白无故增加XAP的容量,也验证了有得必有失道理,鱼与熊掌应该如何取舍呢,先来看看这个实现方式吧。
970 0
|
算法 机器人 定位技术
算法学习之路|hdu 1035 Robot Motion(模拟)
给一个地图,由ESWN(东南西北)组成,机器人根据脚下的指令移动,求如果机器人能走出地图,走的步数多少,如果不能走出,求每绕一圈的步数和绕圈之前走的步数。
1067 0
|
Web App开发 人工智能 PHP
|
机器学习/深度学习 自然语言处理 搜索推荐
PaperWeekly 第十三期--最新文章解读
引言 本期的PaperWeekly一共分享四篇最近arXiv上放出的高质量paper,包括:机器翻译、表示学习、推荐系统和聊天机器人。人工智能及其相关研究日新月异,本文将带着大家了解一下以上四个研究方向都有哪些最新进展。
1813 0