提交时间:2024-01-08 13:30:54
运行 ID: 24614
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double int n; struct tri{ int x,y,l; inline int fl(int Y){ if(Y>=y+l||Y<y)return -1; return 2*x-1; } inline int fr(int Y){ if(Y>=y+l||Y<y)return -1; return 2*(x+l-(Y-y)-1)-1+1; } friend bool operator<(const tri A,const tri B){ if(A.x==B.x)return A.l<B.l; else return A.x<B.x; } }LT[110],RT[110]; inline bool cmpl(tri A,tri B){ if(A.x==B.x)return A.l<B.l; else return A.x<B.x; } inline bool cmpr(tri A,tri B){ return A.x+A.y+A.l<B.x+B.y+B.l; } int l[110],r[110],b[210],d[210],L,R; signed main (){ //freopen("triangle.in","r",stdin); //freopen("triangle.out","w",stdout); ios::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++) cin>>LT[i].x>>LT[i].y>>LT[i].l //LT[i]={1,1,(int)1e6} ,RT[i]=LT[i]; sort(LT+1,LT+n+1,cmpl); sort(RT+1,RT+n+1,cmpr); double res=0; for(int Y=1;Y<=2e6;Y++){ L=0,R=0; for(int i=1;i<=n;i++){ int x=LT[i].fl(Y); if(x!=-1&&x!=l[L])l[++L]=x; else if(x==l[L])--L; x=RT[i].fr(Y); if(x!=-1&&x!=r[R])r[++R]=x; else if(x==r[R])--R; } if(!L&&!R)continue; //cout<<L<<" "<<R<<endl; //continue; int cnt=0; int itl=1,itr=1; l[L+1]=1e9; r[R+1]=1e9; while(itl<=L||itr<=R){ if(l[itl]<r[itr]){ b[++cnt]=l[itl]; l[itl]=cnt; ++itl; } else{ b[++cnt]=r[itr]; r[itr]=cnt; ++itr; } while(itl<=L&&l[itl]==b[cnt]) l[itl]=cnt,++itl; while(itr<=R&&r[itr]==b[cnt]) r[itr]=cnt,++itr; } //cout<<itl<<" "<<itr<<" "<<L<<" "<<R<<" "<<cnt<<endl; for(int i=1;i<=L;i++)d[l[i]]^=1; for(int i=1;i<=R;i++)d[r[i]]^=1; for(int i=1;i<cnt;i++){ d[i]^=d[i-1]; if(d[i])res+=b[i+1]-b[i]; } for(int i=1;i<=cnt;i++) d[i]=0; } printf("%.1Lf",res/2); cout.flush(); fclose(stdin); fclose(stdout); return 0; }