17行代码AC_Completing the Square(Benelux Algorithm Programming Contest 2016 Preliminary)(计蒜客)

Problem describe

In the heart of your home city, there is an old square, close to the train station, appropriately called Station Square. It used to look like a perfect square: four sides of equal length joined by right angles. However, it hasn’t looked like this for decades, as one of the four corners was destroyed by bombings in the Second World War. After the war, the square was rebuilt as a quarter circle, and it has looked like that ever since. (In other words, it looks like an isosceles right triangle, except that the hypothenuse is not a straight line but a circular arc.) This is illustrated in the figure below, which corresponds with Sample Input 1.
在这里插入图片描述

Figure 1: Illustration of the first example input.

Recently, the city council voted to completely remodel the train station and its surroundings, which includes restoring Station Square to its original state. Therefore they need to determine the exact location of the fourth corner. This task is too complicated for ordinary aldermen, so the city decided to hire a top scientist. That would be you! Please help the city complete the square, and you will be greatly rewarded!

Input

There are three lines of input. Each line contains two integers denoting the xx and yy coordinates of one of the corners of the current square − 1 0 4 ≤ x , y ≤ 1 0 4 -10^4 \leq x,y\leq 10^4 104x,y104

Output

Output one line with two space-separated integers denoting the xx and yy coordinates of the long-lost fourth corner.


思路

此题本质是知矩形的三点坐标,求另一点坐标

x 4 = x 2 + x 3 − x 1 x4=x2+x3-x1 x4=x2+x3x1

y 4 = y 2 + y 3 − y 1 y4=y2+y3-y1 y4=y2+y3y1其中:点4为未知数,点1为已知的直角顶点


#include<cstdio>
struct zuobiao { int x,y; };

zuobiao qiudian(int x1,int y1,int x2,int y2,int x3,int y3) {
    zuobiao g;
    g.x=x1+x3-x2;g.y=y1+y3-y2;
    return g;
}
int main() {
    int x1,y1,x2,y2,x3,y3;
    zuobiao g;
    scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
    if((x1-x2)*(x2-x3)+(y1-y2)*(y2-y3)==0) g=qiudian(x1,y1,x2,y2,x3,y3);
    if((x1-x3)*(x2-x3)+(y1-y3)*(y2-y3)==0) g=qiudian(x1,y1,x3,y3,x2,y2);
    if((x1-x3)*(x2-x1)+(y1-y3)*(y2-y1)==0) g=qiudian(x3,y3,x1,y1,x2,y2);
    printf("%d %d",g.x,g.y);
return 0; }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来老铁干了这碗代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值