poj2826 An Easy Problem?!
Posted liguanlin1124
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj2826 An Easy Problem?!相关的知识,希望对你有一定的参考价值。
题目描述:
题解:
这道题告诉我们POJ的数据是极强的……
计算几何。
有好几个特殊情况,都在这组数据里面。
10 6259 2664 8292 9080 1244 2972 9097 9680 0 1 1 0 1 0 2 1 0 1 2 1 1 0 1 2 0 0 10 10 0 0 9 8 0 0 10 10 0 0 8 9 0.9 3.1 4 0 0 3 2 2 0 0 0 2 0 0 -3 2 1 1 1 4 0 0 2 3 1 2 1 4 0 0 2 3 0 0 1 1 0 0 1 2
代码:
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const double eps = 1e-8; int dcmp(double x) if(fabs(x)<=eps)return 0; return x>0?1:-1; struct Point double x,y; Point() Point(double x,double y):x(x),y(y) Point operator + (const Point&a)constreturn Point(x+a.x,y+a.y); Point operator - (const Point&a)constreturn Point(x-a.x,y-a.y); Point operator * (const double&a)constreturn Point(x*a,y*a); double operator ^ (const Point&a)constreturn x*a.y-y*a.x; a,b,c,d; typedef Point Vector; struct Line Point p; Vector v; Line() Line(Point p,Vector v):p(p),v(v) s,t; int n; bool diff(Line l,Point a,Point b) return dcmp(l.v^(a-l.p))*(l.v^(b-l.p))<=0; Point L_L(Line a,Line b) double t = ((b.p-a.p)^b.v)/(a.v^b.v); return a.p+a.v*t; Point L_Y(Line a,double y) return a.p+a.v*((y-a.p.y)/a.v.y); void work() scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y); if(a.y<b.y)swap(a,b); if(c.y<d.y)swap(c,d); if(a.y<c.y)swap(a,c),swap(b,d); s = Line(a,b-a),t = Line(c,d-c); if(!dcmp(a.y-b.y)||!dcmp(c.y-d.y)||!diff(s,c,d)||!diff(t,a,b)||dcmp(a.x-c.x)*dcmp((a-b)^(c-d))<=0) puts("0.00"); else Point p = L_L(s,t),pp = L_Y(s,c.y); printf("%.2lf\n",fabs(((c-p)^(pp-p))/2)+eps); int main() scanf("%d",&n); while(n--)work(); return 0;
以上是关于poj2826 An Easy Problem?!的主要内容,如果未能解决你的问题,请参考以下文章
POJ 2826 An Easy Problem!(简单数论)
POJ2826 An Easy Problem?!(线段交点,三角形面积)
poj2826 An Easy Problem?! 2012-01-11