1 Отредактировано Rasul Abdulaev (2009-11-26 12:45:49)

Тема: informatics.mccme.ru

http://informatics.mccme.ru/moodle/mod/ … pterid=440

#include <iostream>
#include <cmath>
using namespace std;

struct Point {
    double x,y;
    Point()
    {
        x=y=0;
    }
    Point(double xx,double yy)
    {
        x=xx;
        y=yy;
    }
    
    void read()
    {
        scanf("%lf%lf",&x,&y);
    }

    void write()
    {
        printf("%.6lf %.6lf\n",x,y);
    }
    Point operator-(Point a)
    {
        return Point(x-a.x,y-a.y);
    }
    
    double operator*(Point a)
    {
        return x*a.y-y*a.x;
    }

    double scal(Point a)
    {
        return x*a.x+y*a.y;
    }

    double dist()
    {
        return sqrt(x*x+y*y);
    }
    
    double dist(Point p)
    {
        return sqrt((p.x-x)*(p.x-x)+ (p.y-y)*(p.y-y));
    }

    void makeLen(double l)
    {
        double dist = sqrt(x*x+y*y);
        x*=l/dist;
        y*=l/dist;
    }

};

struct Line {
    double a,b,c;
    
    Line()
    {
        a=b=c=0;
    }
    
    Line(double aa,double bb,double cc)
    {
        a=aa;b=bb;c=cc;
    }

    Line(Point p1,Point p2)
    {
        a=p2.y-p1.y;
        b=p1.x-p2.x;
        c=-(a*p1.x+b*p1.y);
    }

    Point Intersec(Line l)
    {
        Point p = Point((b*l.c-l.b*c)/(a*l.b-l.a*b) , -(a*l.c-l.a*c)/(a*l.b-l.a*b));
        return p;
    }

    double dist(Point p)
    {
        return abs(a*p.x+b*p.y+c)/sqrt(a*a+b*b);
    }                                      
};


Line Normal(Point p,Point p1,Point p2)
{
    Point norm = Point(Line(p1,p2).a,Line(p1,p2).b);    
    if ((p-p1).scal(norm) < 0) norm.x*=-1,norm.y*=-1;    

    norm.makeLen(Line(p1,p2).dist(p));

    return Line(p,p-norm);
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    Point p1,p2,p3;

    p1.read();p2.read();p3.read();

    Line l1 = Normal(p1,p2,p3);
    Line l2 = Normal(p2,p1,p3);

    Point p = l1.Intersec(l2);
    p.write();
 }

vrode vse pravilno. No WA6 test. Pomogite plz.


Idea:
Строим 2 прямых, которые перпендикулярны сторонам и проходят через противоволожные стороне точкам

И находим пересечение этих прямых.

2

Re: informatics.mccme.ru

Строим 2 прямых, которые перпендикулярны сторонам и проходят через противоволожные стороне точкам

И находим пересечение этих прямых.

Там же точка пересечения медиан. http://ru.wikipedia.org/wiki/Медиана_треугольника

Re: informatics.mccme.ru

ой , сорри сылку неправильно дал

Re: informatics.mccme.ru

http://informatics.mccme.ru/moodle/mod/ … pterid=440

5

Re: informatics.mccme.ru

Замени в функции Normal return

Line(p,p-norm);

на     

return Line(p,p+norm);

Также лучше удалить строки

    if ((p-p1).scal(norm) < 0) norm.x*=-1,norm.y*=-1;    

    norm.makeLen(Line(p1,p2).dist(p));

, потому что так будет меньше погрешность.

Re: informatics.mccme.ru

Спасибо.  Ошибка из за погрешности . 

     if ((p-p1).scal(norm) < 0) norm.x*=-1,norm.y*=-1;    
    norm.makeLen(Line(p1,p2).dist(p));

убрал ACCEPTED!!!!