Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
解析几何+高斯迭代 案例都过了 还是WA,求路过的大神帮一下。。//解析几何+高斯迭代 #include <cstdio> #include <cmath> #define PI 3.141592653589793 class Point { public: double x; double y; }; Point p[4]; int iterfactor; double x,y; void setIterFactor(int num) { iterfactor = num; } void setInitStatus(double a,double b) { x = a; y = b; } int main() { while(scanf("%lf %lf %lf %lf %lf %lf", &p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y)!=EOF) { double a1,a2,c,b1,b2,d; a1 = p[3].x - p[1].x; a2 = p[3].y - p[1].y; c = (p[3].x + p[1].x) * a1 + (p[3].y + p[1].y) * a2; b1 = p[2].y - p[1].y; b2 = p[2].x - p[1].x; d = (p[2].y + p[1].y) * b1 + (p[2].x + p[1].x) * b2; if(a1==0&&b1==0) { y = (p[1].y + p[3].y) / 2.0; x = (p[1].x + p[2].x) / 2.0; } else if(a1==0) { a1 = p[3].x - p[2].x; a2 = p[3].y - p[2].y; c = (p[3].x + p[2].x) * a1 + (p[3].y + p[2].y) * a2; y = (p[1].y + p[3].y) / 2.0; x = (1.0 / (2.0 * a1)) * (c - 2.0 * a2 * y); } else if(b1==0) { b1 = p[2].y - p[3].y; b2 = p[2].x - p[3].x; d = (p[2].y + p[3].y) * b1 + (p[2].x + p[3].x) * b2; x = (p[1].x + p[2].x) / 2.0; y = (1.0 / (2.0 * b1)) * (d - 2.0 * b2 * x); } else { setIterFactor(11); setInitStatus(0,0); while(iterfactor--) { x = (1.0 / (2.0 * a1)) * (c - 2.0 * a2 * y); y = (1.0 / (2.0 * b1)) * (d - 2.0 * b2 * x); } } double L1_x = x - p[1].x; double L1_y = y - p[1].y; double r = sqrt(L1_x*L1_x+L1_y*L1_y); double circumference = 2 * PI * r; printf("%.2lf\n",circumference); } } 会不会是有些输入的迭代矩阵用高斯迭代不收敛,求大神帮忙看看问题出在哪。。 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator