Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水~~~~1A了

Posted by ecjtu_yuweiwei at 2014-08-02 19:15:11 on Problem 1329
#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
#include<vector>
#define LL long long
#define IT __int64
#define zero(x) fabs(x)<eps
#define mm(a,b) memset(a,b,sizeof(a))
const int INF=0x7fffffff;
const double inf=1e8;
const double eps=1e-10;
const double PI=acos(-1.0);
const int Max=20001;
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
    Node(const double &_x=0, const double &_y=0) : x(_x), y(_y) {}
    void input()
    {
        cin>>x>>y;
    }
    void output()
    {
        cout<<x<<" "<<y<<endl;
    }
}point;
point A,B,C;
point AB,BC;
point Center;
double k1,k2,k3,k4,R;
double b1,b2;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
double slope(point u,point v)
{
    if(sign(v.x-u.x)==0)
        return INF;
    else
        return (v.y-u.y)/(v.x-u.x);
}
int main()
{
    int n,m,i,j;
    while(cin>>A.x>>A.y)
    {
        B.input();
        C.input();
        AB.x=(A.x+B.x)/2;
        AB.y=(A.y+B.y)/2;
        BC.x=(B.x+C.x)/2;
        BC.y=(B.y+C.y)/2;
        k1=slope(A,B);
        k2=slope(B,C);
        Center.x=INF;
        Center.y=INF;
        if(k1==INF)
        {
            k3=0;
            Center.y=AB.y;
        }
        if(k2==INF)
        {
            k4=0;
            Center.y=BC.y;
        }
        if(k1==0)
        {
            k3=INF;
            Center.x=AB.x;
        }
        if(k2==0)
        {
            k4=INF;
            Center.x=BC.x;
        }
        if(Center.x!=INF&&Center.y!=INF)
        {
            //cout<<"111"<<endl;
            R=Distance(Center,A);
            char a,b,c;
            double res;
            res=pow(Center.x,2)+pow(Center.y,2)-pow(R,2);
            if(Center.x<0)
                a='+';
            else
                a='-';
            if(Center.y<0)
                b='+';
            else
                b='-';
            if(res<0)
                c='-';
            else
                c='+';
            cout<<"(x "<<a<<" ";
            cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.x)<<")^2 + (y "<<b<<" ";
            cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.y)<<")^2 = ";
            cout<<setprecision(3)<<setiosflags(ios::fixed)<<R<<"^2"<<endl;

            cout<<"x^2 + y^2 "<<a<<" "<<fabs(2*Center.x)<<"x "<<b<<" "<<fabs(2*Center.y)<<"y "<<c<<" "<<fabs(res)<<" = 0"<<endl;
        }
        else
        {
            if(Center.x==INF&&Center.y==INF)
            {
                k3=-1.0/k1;
                k4=-1.0/k2;
                //cout<<"222"<<endl;
               // AB.output();
               // BC.output();
                b1=AB.y-k3*AB.x;
                b2=BC.y-k4*BC.x;
                //cout<<k3<<" "<<k4<<" "<<b1<<" "<<b2<<endl;
                Center.x=(b2-b1)/(k3-k4);
                Center.y=k3*Center.x+b1;
                //cout<<Center.x<<" "<<Center.y<<endl;
                R=Distance(Center,A);
                //cout<<"ok:: "<<Distance(Center,B)<<" "<<Distance(Center,C)<<endl;
                char a,b,c;
                double res;
                res=pow(Center.x,2)+pow(Center.y,2)-pow(R,2);
                if(Center.x<0)
                    a='+';
                else
                    a='-';
                if(Center.y<0)
                    b='+';
                else
                    b='-';
                if(res<0)
                    c='-';
                else
                    c='+';
                cout<<"(x "<<a<<" ";
                cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.x)<<")^2 + (y "<<b<<" ";
                cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.y)<<")^2 = ";
                cout<<setprecision(3)<<setiosflags(ios::fixed)<<R<<"^2"<<endl;

                cout<<"x^2 + y^2 "<<a<<" "<<fabs(2*Center.x)<<"x "<<b<<" "<<fabs(2*Center.y)<<"y "<<c<<" "<<fabs(res)<<" = 0"<<endl;
            }
            else
            {
                if(Center.x==INF&&Center.y!=INF)
                {
                    if(k3==0)
                    {
                        k4=-1.0/k2;
                        b2=BC.y-k4*BC.x;
                        Center.x=(Center.y-b2)/k4;
                    }
                    if(k4==0)
                    {
                        k3=-1.0/k1;
                        b1=AB.y-k3*AB.x;
                        Center.x=(Center.y-b1)/k3;
                    }
                    //cout<<"222"<<endl;
                    //AB.output();
                    //BC.output();
                    //cout<<k3<<" "<<k4<<" "<<b1<<" "<<b2<<endl;
                    //Center.x=(b2-b1)/(k3-k4);

                    //cout<<Center.x<<" "<<Center.y<<endl;
                    R=Distance(Center,A);
                    //cout<<"ok:: "<<Distance(Center,B)<<" "<<Distance(Center,C)<<endl;
                    char a,b,c;
                    double res;
                    res=pow(Center.x,2)+pow(Center.y,2)-pow(R,2);
                    if(Center.x<0)
                        a='+';
                    else
                        a='-';
                    if(Center.y<0)
                        b='+';
                    else
                        b='-';
                    if(res<0)
                        c='-';
                    else
                        c='+';
                    cout<<"(x "<<a<<" ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.x)<<")^2 + (y "<<b<<" ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.y)<<")^2 = ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<R<<"^2"<<endl;

                    cout<<"x^2 + y^2 "<<a<<" "<<fabs(2*Center.x)<<"x "<<b<<" "<<fabs(2*Center.y)<<"y "<<c<<" "<<fabs(res)<<" = 0"<<endl;
                }
                else if(Center.x!=INF&&Center.y==INF)
                {
                    if(k3==INF)
                    {
                        k4=-1.0/k2;
                        b2=BC.y-k4*BC.x;
                        Center.y=k4*Center.x+b2;
                    }
                    if(k4==INF)
                    {
                        k3=-1.0/k1;
                        b1=AB.y-k3*AB.x;
                        Center.y=k3*Center.x+b1;
                    }
                    R=Distance(Center,A);
                    //cout<<"ok:: "<<Distance(Center,B)<<" "<<Distance(Center,C)<<endl;
                    char a,b,c;
                    double res;
                    res=pow(Center.x,2)+pow(Center.y,2)-pow(R,2);
                    if(Center.x<0)
                        a='+';
                    else
                        a='-';
                    if(Center.y<0)
                        b='+';
                    else
                        b='-';
                    if(res<0)
                        c='-';
                    else
                        c='+';
                    cout<<"(x "<<a<<" ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.x)<<")^2 + (y "<<b<<" ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<fabs(Center.y)<<")^2 = ";
                    cout<<setprecision(3)<<setiosflags(ios::fixed)<<R<<"^2"<<endl;

                    cout<<"x^2 + y^2 "<<a<<" "<<fabs(2*Center.x)<<"x "<<b<<" "<<fabs(2*Center.y)<<"y "<<c<<" "<<fabs(res)<<" = 0"<<endl;
                }
            }
        }
        cout<<endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator