gym101808 E

时间:2021-11-15 12:11:25

提问:我是什么品种的傻逼?

哇看到积水兴高采烈啊。然后就走上了一条不归路。

为什么不归呢,因为我这个法子就是不对的,我总是在想很多很多点围成的一块区域,然后求这一块区域的面积。

然后尝试了各种扫描方法,递增序列,找最低,找最高啊什么的。

自闭。

搜题解:考虑所有相邻的两个点,和他们两边的制高点。那么面积可能是 梯形(制高点高),直角三角形(相交),0.

然后就完了。。。

哇小学数学题难死了啊。

我是智障啊。

 #include <bits/stdc++.h>
using namespace std;
typedef double db;
const int N = 1e5+;
const db eps=1e-;
const db pi=acos(-);
int sign(db k){
if (k>eps) return ; else if (k<-eps) return -; return ;
}
int cmp(db k1,db k2){ return sign(k1-k2);}
struct point {
db x,y;
point operator + (const point &k1) const{return (point){k1.x+x,k1.y+y};}
point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};}
point operator * (db k1) const{return (point){x*k1,y*k1};}
point operator / (db k1) const{return (point){x/k1,y/k1};}
db abs(){ return sqrt(x*x+y*y);}
db dis(point k1){ return (*this-k1).abs();}
};
db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;}
db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;}
point proj(point k1,point k2,point q){
point k=k2-k1;return k1+k*(dot(q-k1,k)/k.abs());
}
point getLL(point k1,point k2,point k3,point k4){
db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2);
}
db area(vector<point> A){ //
db ans=;
for (int i=;i<A.size()-;i++)
ans+=cross(A[i]-A[],A[i+]-A[]);
return ans/;
}
int t,n;
point a[N];
db pre[N],las[N];//
vector<point> v;
int main(){
//freopen("awsl.in","r",stdin);
scanf("%d",&t);
while (t--){
memset(pre,, sizeof(pre));
memset(las,, sizeof(las));
memset(a,, sizeof(a));
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lf%lf",&a[i].x,&a[i].y);
}
for(int i=;i<=n;i++){
pre[i]=max(pre[i-],a[i].y);
}
for(int i=n;i>=;i--){
las[i]=max(las[i+],a[i].y);
}
db ans = ;
for(int i=;i<n;i++){
if(a[i].y>a[i+].y){
db cut = min(min(las[i+],pre[i+]),min(las[i],pre[i]));
if(cut>=a[i].y){
ans+=(cut-a[i].y+cut-a[i+].y)*(a[i+].x-a[i].x)/;
} else if(cut>a[i+].y){
point p1 = point{1.0,cut};
point p2 = point{2.0,cut};
point xxx = getLL(p1,p2,a[i],a[i+]);
ans+=(xxx.y-a[i+].y)*(a[i+].x-xxx.x)/;
}
} else{
db cut = min(min(las[i+],pre[i+]),min(las[i],pre[i]));
if(cut>=a[i+].y){
ans+=(cut-a[i].y+cut-a[i+].y)*(a[i+].x-a[i].x)/;
} else if(cut>a[i].y){
point p1 = point{1.0,cut};
point p2 = point{2.0,cut};
point xxx = getLL(p1,p2,a[i],a[i+]);
ans+=(xxx.y-a[i].y)*(xxx.x-a[i].x)/;
}
}
}
printf("%.10f\n",ans);
}
}