uva1398 线性扫描

/* ***********************************************
Author        :fisty
Created Time  :2014/12/23 21:56:54
File Name     :uva1398.cpp
************************************************ */

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define MAX_N 100000+100
void update(int x, int a, int w, double& L, double& R){
    //0 < x + at < w
    if(a == 0){
        if(x <= 0 || x >= w) R = L - 1;   //无解
    }else if(a > 0){
        // -x/a < t < (w-x)/a
        L = max(L, -(double)x/(double)a);
        R = min(R, (double)(w-x)/(double)a);
    }else{
        //a < 0
        L = max(L, (double)(w-x)/(double)a);
        R = min(R, -(double)x/(double)a);
    }
}
struct node{
    double x;
    int type;
    //node(double _x = 0, int _type = 0):x(_x), type(_type){}
    bool operator < (const node& a) const {
        return x < a.x || (x == a.x && type > a.type);
    }

}event[MAX_N*2];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--){
        int n,w, h;
        int e = 0;
        cin >> w >> h;
        cin >> n;
        //printf("w:%d  h:%d  n:%d\n", w, h, n);
        for(int i = 0;i < n; i++){
            int x, y, a, b;
            cin >> x >> y >> a >> b;
            //printf("%d  %d  %d  %d\n", x,y,a,b);
            double L = 0, R = 1e9;
            update(x , a, w , L, R);
            update(y , b, h , L, R);
            //printf("L:%d  R:%d\n",L,R);
            if(R > L){
                event[e++] = (node){L, 0};
                event[e++] = (node){R, 1};
            }
        }
        sort(event, event + e);
        int cnt = 0, ans = 0;
        for(int i = 0;i < e; i++){
            if(event[i].type == 0){
                ans = max(ans, ++cnt);
            }else{
                cnt--;
            }   
        }
        cout << ans << endl;
    }
    return 0;   
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值