mobile

来源:互联网 发布:形势与政策网络课答案 编辑:程序博客网 时间:2024/04/29 17:57
//mobile 题目来自Mr.S#include<stdio.h>#include<iostream>#include<algorithm>#include<memory.h>#include<vector>#include<math.h>#define Sleft(x)   ((x<<1))#define Sright(x)  ((x<<1|1))#define Sfather(x) ((x>>1))using namespace std;const int MAXN = 101; //max Nconst int root = 1;const int first = 1;const int PASS = 1;const int EMPTY = 0;const double e = 1e-10;int N; //rectangles' quantitystruct Line{     double X_axis;     double Y_axisB,Y_axisT;     int Tag;     Line(double a=0.0,double b=0.0,double c=0.0,int d=1):    X_axis(a),Y_axisB(b),Y_axisT(c),Tag(d){}     bool operator<(const Line &V) const     {       return X_axis<V.X_axis;     }}; //Line nodestruct Line S[MAXN*2]; //Line Gint tot; // Lines' quantity int sumy; // scanning Line's quantitydouble Y_axis[MAXN*2];struct Tree {     double Len;     int L,R;     int Cover;     Tree(double a=0.0,int b=0,int c=0,int d=0):     Len(a),L(b),R(c),Cover(d){}}; //Segment Tree nodestruct Tree T[MAXN*MAXN]; //Segment Treedouble ans = 0.0; //answerint times = 0;void put(){    printf("%d %.2lf\n",times,ans);}void Build_Tree(int t,int s,int e){    T[t]=Tree(0.0,s,e,0);    int mid = (s+e)/2;   if (s>=e) return ;    if (s+1<e) Build_Tree(Sleft(t),s,mid);    if (s+1<e) Build_Tree(Sright(t),mid,e);}void init(){    int i;    tot=sumy=0;    ans=0.0;    memset(Y_axis,0,sizeof(Y_axis));    for (i=1;i<=N;i++)    {      double xi,yi;      double ri;      scanf("%lf %lf %lf",&xi,&yi,&ri);      S[++tot]=Line(xi-ri,yi-ri,yi+ri,1);      S[++tot]=Line(xi+ri,yi-ri,yi+ri,-1);      Y_axis[++sumy]=yi-ri;      Y_axis[++sumy]=yi+ri;    }    sort(Y_axis+1,Y_axis+sumy+1);    sort(S+1,S+tot+1);    sumy = unique(Y_axis+1,Y_axis+sumy+1)-Y_axis-1;    Build_Tree(root,1,sumy);}void Calc(int t){    if (T[t].Cover!=EMPTY)    T[t].Len=Y_axis[T[t].R]-Y_axis[T[t].L];    else if (T[t].L+1==T[t].R) T[t].Len=0;    else T[t].Len=T[Sleft(t)].Len+T[Sright(t)].Len;}void Update(int t,int s,int e,int tag){    if (s>=e) return ;    int mid = (T[t].L+T[t].R)/2;    if (s<=T[t].L&&e>=T[t].R)    {     T[t].Cover+=tag;     Calc(t);     return ;   }   if (e<=mid) Update(Sleft(t),s,e,tag);   else if (s>=mid) Update(Sright(t),s,e,tag);   else Update(Sleft(t),s,mid,tag),Update(Sright(t),mid,e,tag);   Calc(t);}void work(){    int i,j;    for (i=1;i<=tot;i++)    {      if (i!=first) ans+=T[root].Len*(S[i].X_axis-S[i-1].X_axis);      j = i;      while (j<=tot&&(i==j||fabs(S[j].X_axis-S[j-1].X_axis)<e))      {         int l=lower_bound(Y_axis+1,Y_axis+sumy+1,S[j].Y_axisB)-Y_axis;         int r=lower_bound(Y_axis+1,Y_axis+sumy+1,S[j].Y_axisT)-Y_axis;         Update(root,l,r,S[j].Tag);         j++;      }      i = j-1;    }}void groups(){    while (PASS)    {       scanf("%d",&N);       if (N==EMPTY) return ;       times++;       init();       work();       put();    }}int main(){    freopen("mobile.in","r",stdin);    freopen("mobile.out","w",stdout);    groups();    return 0;}


—————————————————————————————————

本文原创自Sliencecsdn技术博客。

本博客所有原创文章请以链接形式注明出处。

欢迎关注本技术博客,本博客的文章会不定期更新。


大多数人想要改造这个世界,但却罕有人想改造自己。

世上没有绝望的处境,只有对处境绝望的人。

                                              ————By slience

—————————————————————————————————


0 0
原创粉丝点击