太自闭了。。。明明很水的说。。。
有三种为0的情况。一种是有水平,一种是没交点。
第三种有点难想啊。就是下面那个板子被上面的挡住了,,雨水进不去。。。
关键是我翻了翻discuss找到了这种数据,,但是脑子短路了不知道怎么写。。。
我们只要把下面那个端点向上延长!看和上面的板子有没有交点就行了啊!还是看了kuangbin的代码受到的启发。。。
哇我是傻逼啊。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <iomanip> 6 7 using namespace std; 8 typedef double db; 9 const db eps = 1e-6; 10 const db pi = acos(-1); 11 int sign(db k){if(k>eps)return 1; else if(k<-eps)return -1;return 0;} 12 int cmp(db k1,db k2){ return sign(k1-k2);} 13 struct point{ 14 db x,y; 15 point operator+(const point &k1)const { return point{k1.x+x,k1.y+y};} 16 point operator - (const point &k1) const{return (point){x-k1.x,y-k1.y};} 17 point operator * (db k1) const{return (point){x*k1,y*k1};} 18 point operator / (db k1) const{return (point){x/k1,y/k1};} 19 db abs(){ return sqrt(x*x+y*y);} 20 }; 21 db cross(point k1,point k2){ return k1.x*k2.y-k1.y*k2.x;} 22 db dot(point k1,point k2){ return k1.x*k2.x+k1.y*k2.y;} 23 int intersect(db l1,db r1,db l2,db r2){ 24 if (l1>r1) swap(l1,r1); if (l2>r2) swap(l2,r2); return cmp(r1,l2)!=-1&&cmp(r2,l1)!=-1; 25 } 26 int checkSS(point k1,point k2,point k3,point k4){ 27 return intersect(k1.x,k2.x,k3.x,k4.x)&&intersect(k1.y,k2.y,k3.y,k4.y)&& 28 sign(cross(k3-k1,k4-k1))*sign(cross(k3-k2,k4-k2))<=0&& 29 sign(cross(k1-k3,k2-k3))*sign(cross(k1-k4,k2-k4))<=0; 30 } 31 point getLL(point k1,point k2,point k3,point k4){ 32 db w1=cross(k1-k3,k4-k3),w2=cross(k4-k3,k2-k3); return (k1*w2+k2*w1)/(w1+w2); 33 } 34 point p[6]; 35 int t; 36 int main(){ 37 ios::sync_with_stdio(false); 38 cout<<fixed<<setprecision(2); 39 cin>>t; 40 while (t--) { 41 for (int i = 1; i <= 4; i++) { 42 cin >> p[i].x >> p[i].y; 43 } 44 bool f=1; 45 if(cmp(p[1].y,p[2].y)==0)f=0; 46 if(cmp(p[3].y,p[4].y)==0)f=0; 47 if(!checkSS(p[1],p[2],p[3],p[4]))f=0; 48 if(!f){ 49 cout<<0.00<<endl; 50 continue; 51 } 52 point tmp = getLL(p[1],p[2],p[3],p[4]); 53 if(p[1].y<p[2].y) swap(p[1],p[2]); 54 if(p[3].y<p[4].y) swap(p[3],p[4]); 55 if(p[1].y>p[3].y){//maxy=p[1] 56 point ano = getLL(p[1],tmp,p[3],{p[3].x-1,p[3].y}); 57 if (checkSS({p[3].x,p[3].y},{p[3].x,20000},ano,p[1])){ 58 cout<<0.00<<endl; 59 continue; 60 } 61 db ans = cross(p[3]-tmp,ano-tmp)/2; 62 ans=abs(ans); 63 cout<<ans<<endl; 64 } else{ 65 point ano = getLL(p[3],tmp,p[1],{p[1].x-1,p[1].y}); 66 if (checkSS({p[1].x,p[1].y},{p[1].x,20000},ano,p[3])){ 67 cout<<0.00<<endl; 68 continue; 69 } 70 db ans = cross(p[1]-tmp,ano-tmp)/2; 71 ans=abs(ans); 72 cout<<ans<<endl; 73 } 74 } 75 } 76 /** 77 1 78 0 0 10 10 79 0 0 8 9 80 */