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

题倒是很简单就是代码写的有点乱。。。

Posted by zhangxizheng at 2012-05-30 10:27:01 on Problem 1673
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>

using namespace std;

struct point{
    float x,y;
}P[6];

int main(){
//    freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--){
        for(int i=0;i<3;++i){
            scanf("%f %f",&P[i].x,&P[i].y);
        }
        float x1,y1,k2,k1,k3,x2,y2,X,Y,k4;
        if(P[0].x==P[1].x){
            x1=P[0].x;
            y1=P[2].y;
            k2=(y1-P[2].y)/(x1-P[2].x);
            k1=(P[2].y-P[0].y)/(P[2].x-P[0].x);
            x2=(P[1].x+k1*P[1].y-k1*P[0].y+k1*k1*P[0].x)/(k1*k1+1);
            y2=(k1*x2-k1*P[0].x+P[0].y);
            if(x2==P[1].x){
                X=(P[1].x);
                Y=(k1*(P[1].x-P[2].x)+P[2].y);
                printf("%.4f %.4f\n",X,Y);
            }
            else{
                k3=(y2-P[1].y)/(x2-P[1].x);
                X=(y1-k2*x1+k3*x2-y2)/(k3-k2);
                Y=k2*X-k2*x1+y1;
                printf("%.4f %.4f\n",X,Y);
            }
        }
        else{
            if(P[0].x==P[2].x){
                x1=P[0].x;
                y1=P[1].y;
                k2=(y1-P[1].y)/(x1-P[1].x);
                k1=(P[1].y-P[0].y)/(P[1].x-P[0].x);
                x2=(P[2].x+k1*P[2].y-k1*P[0].y+k1*k1*P[0].x)/(k1*k1+1);
                y2=(k1*x2-k1*P[0].x+P[0].y);
                if(x2==P[2].x){
                    X=(P[2].x);
                    Y=(k1*(P[2].x-P[1].x)+P[1].y);
                    printf("%.4f %.4f\n",X,Y);
                }
                else{
                    k3=(y2-P[2].y)/(x2-P[2].x);
                    X=(y1-k2*x1+k3*x2-y2)/(k3-k2);
                    Y=k2*X-k2*x1+y1;
                    printf("%.4f %.4f\n",X,Y);
                }
            }
            else{
                if(P[1].x==P[2].x){
                    x1=P[1].x;
                    y1=P[1].y;
                    k2=(y1-P[1].y)/(x1-P[1].x);
                    k1=(P[0].y-P[1].y)/(P[0].x-P[1].x);
                    x2=(P[2].x+k1*P[2].y-k1*P[1].y+k1*k1*P[1].x)/(k1*k1+1);
                    y2=(k1*x2-k1*P[1].x+P[1].y);
                    if(x2==P[2].x){
                        X=(P[2].x);
                        Y=(k1*(P[2].x-P[0].x)+P[0].y);
                        printf("%.4f %.4f\n",X,Y);
                    }
                    else{
                        k3=(y2-P[2].y)/(x2-P[2].x);
                        X=(y1-k2*x1+k3*x2-y2)/(k3-k2);
                        Y=k2*X-k2*x1+y1;
                        printf("%.4f %.4f\n",X,Y);
                    }
                }
                else{
                    k1=(P[1].y-P[0].y)/(P[1].x-P[0].x);
                    x1=(P[2].x+k1*P[2].y-k1*P[0].y+k1*k1*P[0].x)/(k1*k1+1);
                    y1=k1*x1-k1*P[0].x+P[0].y;
                    k2=(P[2].y-P[0].y)/(P[2].x-P[0].x);
                    x2=(P[1].x+k2*P[1].y-k2*P[0].y+k2*k2*P[0].x)/(k2*k2+1);
                    y2=(k2*x2-k2*P[0].x+P[0].y);
                    if(x1==P[2].x){
                        k4=(y2-P[1].y)/(x2-P[1].x);
                        X=P[2].x;
                        Y=k4*(P[2].x-P[1].x)+P[1].y;
                        printf("%.4f %.4f\n",X,Y);
                    }
                    else{
                        if(x2==P[1].x){
                            k3=(y1-P[2].y)/(x1-P[2].x);
                            X=P[1].x;
                            Y=(k3*(P[1].x-P[2].x)+P[2].y);
                            printf("%.4f %.4f\n",X,Y);
                        }
                        else{
                            k3=(y1-P[2].y)/(x1-P[2].x);
                            k4=(y2-P[1].y)/(x2-P[1].x);
                            X=(P[2].y-k3*P[2].x-P[1].y+k4*P[1].x)/(k4-k3);
                            Y=(k3*X-k3*P[2].x+P[2].y);
                            printf("%.4f %.4f\n",X,Y);
                        }
                    }
                }
            }
        }
    }
    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