CFボス195(div 2)A:Vasily the Bear and Triangle

3029 ワード

http://codeforces.com/contest/336/problem/A
 
 
Vasily the bear has a favorite rectangle,it has one vertex at point(0,̵0),and the opposite vertex at point(x,?y).Of course,the sides of Vasya's farite rectores.parate the.ores.parectores.
Vasya also love s triangles,if the triangles have one vertex at point B?=?(0,8201).That's today he asks to find two points A?=;(x 1,820)(x 1,x1,tototototototos))))s s s=thethe.inininininintsA(x=820)(x=_)=_)=_)(x 1,x1,eb=_)(x 1,eb=_)(x 1,x1,820))(x 1,x1,x1,
  • the coordinans of points:x 1,x 2,y 1,y 2 are integers.Besides,the follwing inequation holds:x 1*<8201;x 2;
  • the triangle formed by point A,B and C is rectanglar and isoscers( is right);
  • all points of the favorite rectangle are located inside or on the border of triangle ABC.
  • the ara of triangle ABC is as small as possible.
  • Help the bear、find the required points.It is not so hard to proof that these points are.
    Input
    The first line contains two integers x,?y(?-?109̵≦?x,?y≠109,?x≠
    Output
    Print in the single line four integers x 1,̵y1,̵x2,the coordinas of the required points.
    Sample test(s)
    Input
    10 5
    
    Output
    0 15 15 0
    
    Input
    -10 5
    
    Output
    -15 0 0 15
    
    ノート
    CF#195(div2) A:Vasily the Bear and Triangle_第1张图片
    Figure to the first sample
     
     
    x,y軸を直角にした二等辺直角三角形は、斜辺の点を与え、斜辺の二つの端点を求めて、まずxの小さい点を出力します.
    構想:直線方程式y=k*x+dを求めて、k、dを求めて、すぐできます.
     
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
        double x,y,a[2],b[2],k,m;
        while(~scanf("%lf%lf",&x,&y))
        {
            if(x*y>0)//   -1
            {
                k = -1;
                m = y+x;
                a[0] = -m/k;
                a[1] = 0;
                b[0] = 0;
                b[1] = m;
            }
            else//   1
            {
                k = 1;
                m = y-x;
                a[0] = -m/k;
                a[1] = 0;
                b[0] = 0;
                b[1] = m;
            }
            if(a[0]<b[0])
            {
                printf("%.0lf %.0lf %.0lf %.0lf
    ",a[0],a[1],b[0],b[1]); } else { printf("%.0lf %.0lf %.0lf %.0lf
    ",b[0],b[1],a[0],a[1]); } } return 0; }