一个对精度要求比较高的题。
如果两个线段没交点,那么肯定是0。有交点也不一定就有水,水可以进不来。
最后答案要加一个eps,防止出现-0.00的答案
#include#include #include #include #include #include #include
using namespace std;struct point{ double x; double y; point(){} point(double a,double b){x=a;y=b;}};struct Line{ double a,b,c;}line1,line2;double a,b,c,d,e,f,g,h;vector v;int T;const double eps=1e-8;#define zero(x)(((x)>0?(x):(-x)) eps;}int dot_online_in(point p,point l1,point l2){ return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x) jiao.y&&fabs(p1.y-jiao.y)>eps) v.push_back(p1); if(p2.y>jiao.y&&fabs(p2.y-jiao.y)>eps) v.push_back(p2); if(p3.y>jiao.y&&fabs(p3.y-jiao.y)>eps) v.push_back(p3); if(p4.y>jiao.y&&fabs(p4.y-jiao.y)>eps) v.push_back(p4); if(v.size()==2) { if((v[0].x<=jiao.x&&v[1].x>=jiao.x)||(v[1].x<=jiao.x&&v[0].x>=jiao.x)) { if(v[0].y>v[1].y) swap(v[0],v[1]); point jiao2=jiaodian(v[0].x,v[0].y,20000,v[0].y,jiao.x,jiao.y,v[1].x,v[1].y); ans=Area(jiao,jiao2,v[0]); } else { if(fabs((v[0].y-jiao.y)/(v[0].x-jiao.x)) =fabs(v[1].x-jiao.x)){} else { if(v[0].y>v[1].y) swap(v[0],v[1]); point jiao2=jiaodian(v[1].x,v[1].y,jiao.x,jiao.y,v[0].x,v[0].y,20000,v[0].y); ans=Area(jiao,jiao2,v[0]); } } } } printf("%.2f\n",ans+eps); } return 0;}