zoukankan      html  css  js  c++  java
  • 【扫描法】Meteor UVALive

    传送门:
    https://vjudge.net/problem/UVALive-3905

    分析

    将每个点进出矩形的时间的左右区间 ([L, R]) 处理出来,这样就可以在一维的时间轴做扫描法了。

    细节&技巧:

    1. 注意到在矩形边界的点不计入贡献,因此处理出来的时间区间均为开区间,在维护贡献 (cnt) 之前的排序中,在时间点相等的时候,指定出队的点优先级更高以使贡献被正确维护。

    2. update 操作中出现了除数运算,如果需要避免使用 double,可以利用所有可能出现的速度的最小公倍数 (lcm)。注意到题目中速度的范围在 ([1,10]),因此 (lcm=2520)。只需将时间乘上 (lcm) 即可避免使用 double

    #pragma GCC optimize("O3")
    #include<bits/stdc++.h>
    using namespace std;
    
    #define endl '
    '
    #define debug(x) cerr << #x << ": " << x << endl
    #define pb push_back
    #define eb emplace_back
    #define set0(a) memset(a,0,sizeof(a))
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define INF 0x3f3f3f3f
    #define ll_INF 0x7f7f7f7f7f7f7f7f
    
    using pii = pair<int, int>;
    using pdd = pair<double, double>;
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vb = vector<bool>;
    using vpii = vector<pii>;
    using ll = long long;
    using ull = unsigned long long;
    
    #define int ll
    
    inline void read(int &x) {
        int s=0;x=1;
        char ch=getchar();
        while(ch<'0'||ch>'9') {if(ch=='-')x=-1;ch=getchar();}
        while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
        x*=s;
    }
    
    const int N=1e5+5, D=2520;
    
    int w, h;
    int n;
    
    struct Event{
    	int x, type;
    	bool operator < (const Event &o)const{
    		return x==o.x? type<o.type: x<o.x;
    	}
    }e[N<<1];
    int tot;
    
    void update(int x, int v, int p, int &L, int &R){
    	if(v==0){
    		if(x<=0 || x>=p) L=INF, R=-INF;
    	}
    	else if(v>0) L=max(L, -x*D/v), R=min(R, (p-x)*D/v);
    	else L=max(L, (x-p)*D/-v), R=min(R, x*D/-v);
    }
    
    signed main(){
    	int T; cin>>T;
    	while(T--){
    		read(w), read(h);
    		read(n);
    		
    		tot=0;
    		rep(i,1,n){
    			int x, y, a, b; read(x), read(y), read(a), read(b);
    			int L=0, R=INF; // time of in and out
    			update(x, a, w, L, R); // x axis of in and out
    			update(y, b, h, L, R); // y axis of in and out
    			if(L<R) e[++tot]={L, 1}, e[++tot]={R, -1};
    		}
    		
    		sort(e+1, e+1+tot);
    		
    		int res=0, cnt=0;
    		rep(i,1,tot){
    			cnt+=e[i].type;
    			res=max(res, cnt);
    		}
    		cout<<res<<endl;
    	}
        return 0;
    }
    
  • 相关阅读:
    hdu1247 字典树或者hash
    hdu1247 字典树或者hash
    hdu1251 hash或者字典树
    hdu1251 hash或者字典树
    hdu4421 2-sat(枚举二进制每一位)
    hdu4421 2-sat(枚举二进制每一位)
    poj3648 2-sat
    poj3648 2-sat
    hdu 1814 字典序最小的2sat(暴力深搜)
    hdu 1814 字典序最小的2sat(暴力深搜)
  • 原文地址:https://www.cnblogs.com/Tenshi/p/15165976.html
Copyright © 2011-2022 走看看