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 |
为什么是wrong answer。。郁闷 #include<iostream> #include<cstdio> #include<cmath> #include<vector> using namespace std; class Side; //void Side::length(); class Point { public: Point(double a,double b):x(a),y(b) {} //friend void Side::length(); friend Side; private: double x,y; }; class Side { public: Side(double,double,double,double); double coe1(),coe2(),coe3(); double length(); private: Point X,Y; }; Side::Side(double a,double b,double c,double d):X(a,b),Y(c,d){} double Side::length() {return sqrt(pow((X.x-Y.x),2)+pow((X.y-Y.y),2));} double Side::coe1() {return X.y-Y.y;} double Side::coe2() {return Y.x-X.x;} double Side::coe3() {return X.x*(Y.y-X.y)-X.y*(Y.x-X.x);} class Triangle { public: Triangle(double a,double b,double c,double d,double e,double f):X(a,b),Y(c,d),Z(e,f), XY(a,b,c,d),YZ(c,d,e,f),ZX(e,f,a,b) {} double area(); double circum(); private: Point X,Y,Z; Side XY,YZ,ZX; //double AB,BC,CA; }; double Triangle::circum() {return XY.length()+YZ.length()+ZX.length();} double Triangle::area() {return sqrt(0.5*circum()*(0.5*circum()-XY.length())*(0.5*circum()-YZ.length())*(0.5*circum()-ZX.length()));} void solve(double A1,double B1,double C1,double A2,double B2,double C2 ,double & x, double & y) {//cout<<"x="<<(B2*C1-B1*C2)/(A1*B2-A2*B1)<<" y="<<(A2*C1-A1*C2)/(A2*B1-A1*B2)<<endl; x=(B2*C1-B1*C2)/(A1*B2-A2*B1);y=(A2*C1-A1*C2)/(A2*B1-A1*B2); } double max(double a,double b, double c) { double x=0; x=a>b?a:b; x=x>c?x:c; return x; } double min(double a,double b,double c) { double x=a<b?a:b; x=x<c?x:c; return x; } int main() { double x1,y1,x2,y2,x3,y3,h; //cin>>x1>>y1>>x2>>y2>>x3>>y3>>h; vector <double> X1,Y1,X2,Y2,X3,Y3,H; while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>h && x1!=EOF) { X1.push_back(x1); Y1.push_back(y1); X2.push_back(x2); Y2.push_back(y2); X3.push_back(x3); Y3.push_back(y3); } for(vector<double>::size_type i=0;i<X1.size();i++) { x1=X1[i];y1=Y1[i];x2=X2[i];y2=Y2[i];x3=X3[i];y3=Y3[i]; Point A(x1,y1),B(x2,y2), C(x3,y3); Side AB(x1,y1,x2,y2),BC(x2,y2,x3,y3),CA(x3,y3,x1,y1); Triangle ABC(x1,y1,x2,y2,x3,y3); double A1,B1,C1,A2,B2,C2; double x=0,y=0,Qx,Qy; double S=ABC.area(); double d=2*S/(pow(AB.length(),2)+pow(BC.length(),2)+pow(CA.length(),2)); A1=AB.coe1()/sqrt(pow(AB.coe1(),2)+pow(AB.coe2(),2)); B1=AB.coe2()/sqrt(pow(AB.coe1(),2)+pow(AB.coe2(),2)); C1=AB.coe3()/sqrt(pow(AB.coe1(),2)+pow(AB.coe2(),2)); A2=BC.coe1()/sqrt(pow(BC.coe1(),2)+pow(BC.coe2(),2)); B2=BC.coe2()/sqrt(pow(BC.coe1(),2)+pow(BC.coe2(),2)); C2=BC.coe3()/sqrt(pow(BC.coe1(),2)+pow(BC.coe2(),2)); double maxX=max(x1,x2,x3); double minX=min(x1,x2,x3); double maxY=max(y1,y2,y3); double minY=min(y1,y2,y3); solve(A1,B1,d*AB.length()-C1,A2,B2,d*BC.length()-C2,x,y); if(x<=maxX&&x>=minX && y<=maxY&&y>=minY) {Qx=x;Qy=y;} solve(A1,B1,-d*AB.length()-C1,A2,B2,d*BC.length()-C2,x,y); if(x<=maxX&&x>=minX && y<=maxY&&y>=minY) {Qx=x;Qy=y;} solve(A1,B1,-d*AB.length()-C1,A2,B2,-d*BC.length()-C2,x,y); if(x<=maxX&&x>=minX && y<=maxY&&y>=minY) {Qx=x;Qy=y;} solve(A1,B1,d*AB.length()-C1,A2,B2,-d*BC.length()-C2,x,y); if(x<=maxX&&x>=minX && y<=maxY&&y>=minY) {Qx=x;Qy=y;} printf("%.2f",Qx); printf("%.2f\n",Qy); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator