ZOJ 3379 Master Spark

计算出中轴能覆盖到某个点的极角范围,最大覆盖次数即是答案。

首先把中轴和点重合,此时中轴的角度为theta = atan(y/x),

然后以原点为圆心旋转点和抛物线相交求出之间的夹角,

把x = a*y*y 化成极坐标下r cosθ = a *r *r (1 -  cos2θ) ,解方程得到

极角范围应该为[theta-θ, theta+θ]。

有了极角范围,排序以后扫描线。

写的时候须小心的坑点:

1.theta-θ的范围可能超过[0, 2*pi],需要取余。

2.取余以后有可能有end < begin的情况,需要在最左端手动添加事件点。

3.端点是都可以包括的,当极角相同时,入点事件优先于出点事件。

/*********************************************************
*            ------------------                          *
*   author AbyssFish                                     *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<climits>
using namespace std;


typedef long double ld;
const int maxn = 3e4+1;
double x[maxn], y[maxn];

inline ld sqr(ld x){ return x*x; }
const ld DPI = acosl(-1)*2;

typedef pair<ld,int> ev;
#define fi first
#define se second
vector<ev> evs;
#define pb push_back

//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    //cout<<remainder(-1,2);
    int n;
    double a;
    evs.reserve(maxn*3);
    while(~scanf("%d%lf",&n,&a)){
        int i;
        for(i = 0; i < n; i++) scanf("%lf",x+i);
        for(i = 0; i < n; i++) scanf("%lf",y+i);
        ld theta, delta, r, be, ed;
        evs.clear();
        for(i = 0; i < n; i++){
            theta = atan2l(y[i],x[i]);
            r = sqrtl(sqr(x[i])+sqr(y[i]));
            delta = acosl( (-1+sqrtl(1+4*sqr(r)*sqr(a)))/(2*a*r) );
            //if(delta < 0) delta = -delta;
            be = remainderl(theta-delta,DPI);
            ed = remainderl(theta+delta,DPI);
            if(be < 0) be += DPI;
            if(ed < 0) ed += DPI;
            evs.pb(ev(be,-1));
            evs.pb(ev(ed,1));
            if(ed < be){
                evs.pb(ev(0,-1));
            }
        }
        int ans = 0, cur = 0;
        sort(evs.begin(),evs.end());
        for(vector<ev> ::iterator it = evs.begin(); it != evs.end(); it++){
            cur -= it->se;
            //cout<<cur<<endl;
            ans = max(ans,cur);
        }
        printf("%d daze
", ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/jerryRey/p/5041139.html