好不EASY的EasyProblem。。。各种WA啊。。。
注意考虑的情况中有一种是其中一块板在能盛水的情况下会不会被另一个板挡住而没法接住雨水。。。
注意问的是能接多少水而不是能装多少水
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define oo 1e6
#define eps 1e-8
#define nMax 100000
#define pb push_back
#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)
int dcmp(double x){
if(fabs(x)<eps) return 0;
return x>0?1:-1;
}
struct point {
double x,y;
point(double x=0,double y=0): x(x),y(y) {}
void make(double _x,double _y) {x=_x;y=_y;}
void read(){ scanf("%lf%lf",&x,&y); }
double len(){ return sqrt(x*x+y*y); }
friend point operator -(point const& u,point const& v) {
return point(u.x-v.x,u.y-v.y);
}
friend point operator +(point const& u,point const& v) {
return point(u.x+v.x,u.y+v.y);
}
friend double operator *(point const& u,point const& v) {
return u.x*v.y-u.y*v.x;
}
friend double operator ^(point const& u,point const& v) {
return u.x*v.x+u.y*v.y;
}
friend point operator *(double const& k,point const& v) {
return point(k*v.x,k*v.y);
}
friend point operator /(point const& u,double const& k){
return point(u.x/k,u.y/k);
}
friend int dots_online(point,point,point);
};
int dots_online(point a,point b,point c){ return dcmp((a-c)*(b-c))==0; }
typedef struct line{
point a,b;
line() {}
line(point a,point b): a(a),b(b) {}
void make(point _a,point _b) {a=_a;b=_b;}
void read() { a.read(),b.read(); }
friend int intersection(line,line);
} segment;
int parell(line u,line v){
return dcmp((u.a-u.b)*(v.a-v.b)) == 0;
}
int dot_in_line(point p,line l){
return dcmp((l.a-p)*(p-l.b))==0 && dcmp((l.a-p)^(p-l.b))>=0;
}
int sameside(point a,point b,line l){
return dcmp((l.a-a)*(a-l.b)) * dcmp((l.a-b)*(b-l.b)) > 0;
}
int intersection(line u,line v){
if(dots_online(u.a,u.b,v.a) && dots_online(u.a,u.b,v.b))
return dot_in_line(u.a,v) || dot_in_line(u.b,v) || dot_in_line(v.a,u) || dot_in_line(v.a,u);
else
return !sameside(u.a,u.b,v) && !sameside(v.a,v.b,u);
}
point intersection(line u,line v,int ok){
point ret = u.a;
double t = ((u.a-v.a)*(v.a-v.b))/((u.a-u.b)*(v.a-v.b));
ret = ret + t*(u.b-u.a);
return ret;
}
point intersection(line u,double y){
if(dcmp(u.a.y-u.b.y)==0) return point(0,y);
return point((y-u.b.y)/(u.a.y-u.b.y)*(u.a.x-u.b.x)+u.b.x,y);
}
double intersection(line u,double x,int ok){
if(dcmp(u.a.x-u.b.x)==0) return -oo;
return (x-u.b.x)/(u.a.x-u.b.x)*(u.a.y-u.b.y)+u.b.y;
}
int check(line s1,double x2,int k){
/*if(dcmp(intersection(s1,x1,0)-intersection(s2,x1,0))>=0 && \
dcmp(intersection(s1,x2,0)-intersection(s2,x2,0))>=0) return 1;*/
if(k && dcmp(x2-s1.a.x)>=0) return 1;
else if(k) return 0;
if(dcmp(x2-s1.b.x) > 0) return 0;
return 1;
}
segment s1,s2;
vector<double> un;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
int t;
scanf("%d",&t);
while(t--){
s1.read(),s2.read();
if(dcmp(s1.a.x-s1.b.x)>0) swap(s1.a,s1.b);
if(dcmp(s2.a.x-s2.b.x)>0) swap(s2.a,s2.b);
double ans = 0;
if(!parell(s1,s2) && intersection(s1,s2)){
point p=intersection(s1,s2,0);
un.clear();
if(dcmp(s1.a.y-p.y)>0) un.pb(s1.a.y);
if(dcmp(s1.b.y-p.y)>0) un.pb(s1.b.y);
if(dcmp(s2.a.y-p.y)>0) un.pb(s2.a.y);
if(dcmp(s2.b.y-p.y)>0) un.pb(s2.b.y);
point p1,p2;
if(un.size()!=2) ans = 0;
else {
//cout<<un[1]<<endl;
if(dcmp(un[0]-un[1])<0) swap(un[0],un[1]);
p1 = intersection(s1,un[1]);//bug
p2 = intersection(s2,un[1]);
//printf("%.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n",p.x,p.y,p1.x,p1.y,p2.x,p2.y);
ans = 0.5*(p1-p)*(p2-p);
ans = fabs(ans);//printf("%.9lf\n",ans);
}
if(dcmp(ans)){
if(dcmp(p1.x-p.x)>=0 && dcmp(p2.x-p.x)>=0) {
if(dcmp(p1.x-p2.x)>=0) {
if(check(s2,p1.x,0)) ans=0;
}else {
if(check(s1,p2.x,0)) ans=0;
}
}else if(dcmp(p1.x-p.x)<=0 && dcmp(p2.x-p.x)<=0) {
if(dcmp(p1.x-p2.x)<=0) {
if(check(s2,p1.x,1)) ans=0;
}else {
if(check(s1,p2.x,1)) ans=0;
}
}}
}
printf("%.2f\n",ans);
}
return 0;
}