CF#195(div2) A:Vasily the Bear and Triangle

针对已知直角位于原点的等腰直角三角形,本篇介绍如何确定该三角形斜边两端点坐标的方法。通过输入直角三角形内一已知点坐标,利用直线方程计算出斜边两端点坐标,确保所有矩形点位于三角形内部。

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 favorite rectangle are parallel to the coordinate axes.

Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:

  • the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;
  • the triangle formed by point A, B and C is rectangular and isosceles ( is right);
  • all points of the favorite rectangle are located inside or on the border of triangle ABC;
  • the area 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 unique.

Input

The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).

Output

Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.

Sample test(s)
Input
10 5
Output
0 15 15 0
Input
-10 5
Output
-15 0 0 15
Note

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\n",a[0],a[1],b[0],b[1]);
        }
        else
        {
            printf("%.0lf %.0lf %.0lf %.0lf\n",b[0],b[1],a[0],a[1]);
        }
    }

    return 0;
}


 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值