提问:我是什么品种的傻逼?
哇看到积水兴高采烈啊。然后就走上了一条不归路。
为什么不归呢,因为我这个法子就是不对的,我总是在想很多很多点围成的一块区域,然后求这一块区域的面积。
然后尝试了各种扫描方法,递增序列,找最低,找最高啊什么的。
自闭。
搜题解:考虑所有相邻的两个点,和他们两边的制高点。那么面积可能是 梯形(制高点高),直角三角形(相交),0.
然后就完了。。。
哇小学数学题难死了啊。
我是智障啊。
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef double db; 4 const int N = 1e5+5; 5 const db eps=1e-6; 6 const db pi=acos(-1); 7 int sign(db k){ 8 if (k>eps) return 1; else if (k<-eps) return -1; return 0; 9 } 10 int cmp(db k1,db k2){ return sign(k1-k2);} 11 struct point { 12 db x,y; 13 point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};} 14 point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} 15 point operator * (db k1) const{return (point){x*k1,y*k1};} 16 point operator / (db k1) const{return (point){x/k1,y/k1};} 17 db abs(){ return sqrt(x*x+y*y);} 18 db dis(point k1){ return (*this-k1).abs();} 19 }; 20 db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;} 21 db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;} 22 point proj(point k1,point k2,point q){ 23 point k=k2-k1;return k1+k*(dot(q-k1,k)/k.abs()); 24 } 25 point getLL(point k1,point k2,point k3,point k4){ 26 db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2); 27 } 28 db area(vector<point> A){ // 29 db ans=0; 30 for (int i=1;i<A.size()-1;i++) 31 ans+=cross(A[i]-A[0],A[i+1]-A[0]); 32 return ans/2; 33 } 34 int t,n; 35 point a[N]; 36 db pre[N],las[N];// 37 vector<point> v; 38 int main(){ 39 //freopen("awsl.in","r",stdin); 40 scanf("%d",&t); 41 while (t--){ 42 memset(pre,0, sizeof(pre)); 43 memset(las,0, sizeof(las)); 44 memset(a,0, sizeof(a)); 45 scanf("%d",&n); 46 for(int i=1;i<=n;i++){ 47 scanf("%lf%lf",&a[i].x,&a[i].y); 48 } 49 for(int i=1;i<=n;i++){ 50 pre[i]=max(pre[i-1],a[i].y); 51 } 52 for(int i=n;i>=1;i--){ 53 las[i]=max(las[i+1],a[i].y); 54 } 55 db ans = 0; 56 for(int i=1;i<n;i++){ 57 if(a[i].y>a[i+1].y){ 58 db cut = min(min(las[i+1],pre[i+1]),min(las[i],pre[i])); 59 if(cut>=a[i].y){ 60 ans+=(cut-a[i].y+cut-a[i+1].y)*(a[i+1].x-a[i].x)/2; 61 } else if(cut>a[i+1].y){ 62 point p1 = point{1.0,cut}; 63 point p2 = point{2.0,cut}; 64 point xxx = getLL(p1,p2,a[i],a[i+1]); 65 ans+=(xxx.y-a[i+1].y)*(a[i+1].x-xxx.x)/2; 66 } 67 } else{ 68 db cut = min(min(las[i+1],pre[i+1]),min(las[i],pre[i])); 69 if(cut>=a[i+1].y){ 70 ans+=(cut-a[i].y+cut-a[i+1].y)*(a[i+1].x-a[i].x)/2; 71 } else if(cut>a[i].y){ 72 point p1 = point{1.0,cut}; 73 point p2 = point{2.0,cut}; 74 point xxx = getLL(p1,p2,a[i],a[i+1]); 75 ans+=(xxx.y-a[i].y)*(xxx.x-a[i].x)/2; 76 } 77 } 78 } 79 printf("%.10f\n",ans); 80 } 81 }