bzoj 1199 二分暴力

来源:互联网 发布:hbuilder for mac下载 编辑:程序博客网 时间:2024/04/24 11:04

这道题的数据范围是25W...

直接暴力。。。

将所有点按照x排序之后。遍历所有的矩形和圆,用upper_bound和lower_bound寻找出符合图形x坐标的所有点,(位于区间[s,t]),然后暴力枚举刚才寻找的点判断是否在当前形状内。。

好黄好暴力。upper_bound和lower_bound的新用法~~

#include <algorithm>#include <algorithm>#include <iostream>#include<string.h>#include <fstream>#include <math.h>#include <vector>#include <cstdio>#include <string>#include <queue>#include <stack>#include <map>#include <set>#define exp 1e-8#define fi first#define se second#define ll long long#define INF 0x3f3f3f3f#define lson l,mid,rt<<1#define pb(a) push_back(a)#define mp(a,b) make_pair(a,b)#define rson mid+1,r,(rt<<1)+1#define all(a) a.begin(),a.end()#define mm(a,b) memset(a,b,sizeof(a));#define for1(a,b) for(int a=1;a<=b;a++)//1---(b)#define rep(a,b,c) for(int a=b;a<=c;a++)//b---c#define repp(a,b,c)for(int a=b;a>=c;a--)///using namespace std;void bug(string m="here"){cout<<m<<endl;}template<typename __ll> inline void READ(__ll &m){__ll x=0,f=1;char ch=getchar();while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}m=x*f;}template<typename __ll>inline void read(__ll &m){READ(m);}template<typename __ll>inline void read(__ll &m,__ll &a){READ(m);READ(a);}template<typename __ll>inline void read(__ll &m,__ll &a,__ll &b){READ(m);READ(a);READ(b);}template<typename __ll>inline void read(__ll &m,__ll &a,__ll &b,__ll &c){READ(m);READ(a);READ(b);READ(c);}template < class T > T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template < class T > T lcm(T a, T b) { return a / gcd(a, b) * b; }template < class T > inline void rmin(T &a, const T &b) { if(a > b) a = b; }template < class T > inline void rmax(T &a, const T &b) { if(a < b) a = b; }template < class T > T pow(T a, T b) { T r = 1; while(b > 0) { if(b & 1) r = r * a; a = a * a; b /= 2; } return r; }template < class T > T pow(T a, T b, T mod) { T r = 1; while(b > 0) { if(b & 1) r = r * a % mod; a = a * a % mod; b /= 2; } return r; }const int maxn=250000+100;int ans[maxn];struct POINT{    double x,y;int idx;    bool operator <(const POINT &a)const {        return x<a.x;    }    POINT(){}    POINT(double a,double b)    {        x=a,y=b;    }}point[maxn];int cnt_point=0;struct square{    POINT p1,p2;    void read()    {        scanf("%lf %lf %lf %lf",&p1.x,&p1.y,&p2.x,&p2.y);    }    bool insize(POINT tmp)    {        if(tmp.x>p1.x&&tmp.x<p2.x&&tmp.y>p1.y&&tmp.y<p2.y)            return 1;        return 0;    }    void cal()    {        int s=upper_bound(point,point+cnt_point,p1)-point;        int t=lower_bound(point,point+cnt_point,p2)-point-1;        for(int i=s;i<=t;i++)            if(insize(point[i]))                ans[point[i].idx]++;    }}squ[maxn];int cnt_squ=0;struct circle{    POINT p;    double r;    void read()    {        scanf("%lf %lf %lf",&p.x,&p.y,&r);    }    double dist(POINT tmp)    {        return (tmp.x-p.x)*(tmp.x-p.x)+(tmp.y-p.y)*(tmp.y-p.y);    }    bool insize(POINT tmp)    {        if(dist(tmp)<r*r)            return 1;        return 0;    }    void cal()    {        int s=upper_bound(point,point+cnt_point,POINT(p.x-r,0.0))-point;        int t=lower_bound(point,point+cnt_point,POINT(p.x+r,0.0))-point-1;        for(int i=s;i<=t;i++)            if(insize(point[i]))                ans[point[i].idx]++;    }}cir[maxn];int cnt_cir=0;int main(){    int n,m;    read(n,m);    cnt_point=m;    char ch[200];    while(n--)    {        scanf("%s",ch);        if(ch[0]=='r')            squ[cnt_squ++].read();        else cir[cnt_cir++].read();    }    rep(i,0,m-1)scanf("%lf %lf",&point[i].x,&point[i].y),point[i].idx=i;    sort(point,point+m);    rep(i,0,cnt_squ-1)squ[i].cal();    rep(i,0,cnt_cir-1)cir[i].cal();    rep(i,0,m-1)printf("%d\n",ans[i]);    return 0;}


0 0
原创粉丝点击