日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ybtoj洛谷P4406三角形面积并(扫描线)

發布時間:2023/12/3 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ybtoj洛谷P4406三角形面积并(扫描线) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

解析

暴力求出所有三角形之間的所有交點,提出所有的橫坐標。
然后任意兩個相鄰的橫坐標之間的面積都是若干個梯形。
那么就可以求出對于每一個橫坐標截得的三角形長度的并的和,然后加在一起乘高除以二即可。

在這里插入代碼片`#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define debug(...) fprintf(stderr,__VA_ARGS__) //#define ok debug("OK\n") inline ll read() {ll x(0),f(1);char c=getchar();while(!isdigit(c)) {if(c=='-') f=-1;c=getchar();}while(isdigit(c)) {x=(x<<1)+(x<<3)+c-'0';c=getchar();}return x*f; } const int N=2e5+100; const double eps=1e-10; const double inf=1e9;int n,m;struct pt {double x,y; } p[N]; inline pt operator + (const pt a,const pt b) {return (pt) {a.x+b.x,a.y+b.y}; } inline pt operator - (const pt a,const pt b) {return (pt) {a.x-b.x,a.y-b.y}; } inline pt operator * (const double k,const pt a) {return (pt) {k*a.x,k*a.y}; } inline pt operator / (const pt a,const double k) {return (pt) {a.x/k,a.y/k}; } inline pt operator * (const pt a,const double k) {return (pt) {k*a.x,k*a.y}; } inline double operator * (const pt a,const pt b) {return a.x*b.x+a.y*b.y; } inline double operator ^ (const pt a,const pt b) {return a.x*b.y-b.x*a.y; } inline double len (const pt a) {return sqrt(a.x*a.x+a.y*a.y); } inline pt danwei(const pt a) {return a/len(a); } inline pt chui(const pt a) {return (pt) {a.y,-a.x}; } void print(pt o,int op=1) {printf("%.2lf %.2lf",o.x,o.y);putchar(op?'\n':' ');return; } void input(pt &o) {scanf("%lf%lf",&o.x,&o.y); }struct line {pt a,b,d; };void input(line &l) {double a,b,c,d;scanf("%lf%lf%lf%lf",&a,&b,&c,&d);l=(line) {(pt) {a,b},(pt) {c,d},(pt) {c-a,d-b}};return; } void print(line l,int op=1){print(l.a,0);print(l.b,op); } inline line trans(double a,double b,double c,double d) {return (line) {(pt) {a,b},(pt) {c,d},(pt) {c-a,d-b}}; } inline line trans(const pt a,const pt b) {return (line) {a,b,b-a}; } int pos(const line l1,const line l2) {if(abs(l1.d^l2.d)>eps) return 1;else if(abs((l2.a-l1.a)^l1.d)>eps) return 2;else return 3; } pt jiaodian(const line l1,const line l2) {double k=((l2.a-l1.a)^l2.d)/(l1.d^l2.d);return l1.a+(k*l1.d); } pt a[N],b[N],c[N]; line l[N][4]; double q[N]; int cnt; bool ok(line l,pt o){return (l.a.x-eps<o.x&&o.x<l.b.x+eps)||(l.b.x-eps<o.x&&o.x<l.a.x+eps); } struct seg{double l,r;bool operator < (const seg oth)const{return l<oth.l;} }s[N]; int num; line L; double w[5]; void work(int k){int jd(0);//printf("work : %d\n",k);for(int i=1;i<=3;i++){if(abs(l[k][i].d.x)<eps) continue;pt o=jiaodian(l[k][i],L);//print(o,1);if(ok(l[k][i],o)) w[++jd]=o.y;}if(jd>1){++num;s[num].l=s[num].r=w[1];for(int i=2;i<=jd;i++) s[num].l=min(s[num].l,w[i]);for(int i=2;i<=jd;i++) s[num].r=max(s[num].r,w[i]);//printf("(%.2lf %.2lf)\n",s[num].l,s[num].r);} } double calc(double x){num=0;L=trans(x,0,x,1);for(int i=1;i<=n;i++) work(i);sort(s+1,s+1+num);double l=-inf,r=-inf,res=0;for(int i=1;i<=num;i++){if(s[i].l<r+eps) r=max(r,s[i].r);else{res+=r-l;l=s[i].l;r=s[i].r;}}res+=r-l;return res; } signed main() { #ifndef ONLINE_JUDGE//freopen("a.in","r",stdin);//freopen("a.out","w",stdout); #endifreturn 0; } /* 2 0.0 0.0 20.0 28.0 10.0 35.0 -50.0 0.0 -70.8 -33.5 -30.5 -10.5 */`

總結

以上是生活随笔為你收集整理的ybtoj洛谷P4406三角形面积并(扫描线)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。