Content

一个矩形的顶点为 \((0,0)\),其对顶点为 \((x,y)\),现过 \((x,y)\) 作直线,分别交 \(x\) 轴和 \(y\) 轴于 \(A,B\) 两点,使得 \(\triangle OAB\) 为一个等腰直角三角形,求 \(A,B\) 点的坐标。(输出时 \(x\) 坐标小的先输出)

数据范围:\(-10^9\leqslant x,y\leqslant 10^9,x,y\neq 0\)。

Solution

这题是个数学题目,需要用到分类讨论。

这里先把草图给放上,方便大家理解——

当 \(x>0,y>0\),即 \((x,y)\) 在第一象限时,即如上图中 \(D\) 点所示。那么设我们过 \(D\) 点做的直线分别交 \(x,y\) 轴于 \(A_1,B_1\) 两点,并过 \(D\) 点做 \(DH_1\perp OA_1\)。则有 \(\angle DA_1O=45^\circ\)。所以 \(\triangle DH_1A_1\) 是一个等腰直角三角形,所以 \(H_1A_1=DH_1=|x|=x\)。同理,过 \(D\) 点做 \(DH_2\perp OB_1\),则有 \(\angle DB_1O=45^\circ\),所以 \(\triangle DH_2B_1\) 是一个等腰直角三角形,所以 \(B_1H_2=DH_2=|y|=y\)。所以 \(A_1\) 的横坐标为 \(OH_1+DH_1=x+y\),\(B_1\) 的纵坐标为 \(OH_2+B_1H_2=x+y\)。所以最终的结果就是 \(A_1(x+y,0),B_1(0,x+y)\)。

这里以第一象限的为例,其他的就请读者自己去推啦~

Code

#include <cstdio>
using namespace std; int main() {
int a, b;
scanf("%d%d", &a, &b);
if(a > 0 && b > 0) printf("0 %d %d 0", a + b, a + b);
else if(a < 0 && b > 0) printf("%d 0 0 %d", a - b, -a + b);
else if(a < 0 && b < 0) printf("%d 0 0 %d", a + b, a + b);
else if(a > 0 && b < 0) printf("0 %d %d 0", a - b, -a + b);
return 0;
}

CF336A Vasily the Bear and Triangle 题解的更多相关文章

  1. Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle

    水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using name ...

  2. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

  3. cf A. Vasily the Bear and Triangle

    http://codeforces.com/contest/336/problem/A #include <cstdio> #include <cstring> #includ ...

  4. codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Beautiful Strings Vas ...

  5. codeforces 336C Vasily the Bear and Sequence(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Sequence Vasily the b ...

  6. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  7. ZOJ 4081 Little Sub and Pascal's Triangle 题解

    ZOJ 4081 Little Sub and Pascal's Triangle 题解 题意 求杨辉三角第n行(从1开始计数)有几个奇数. 考察的其实是杨辉--帕斯卡三角的性质,或者说Gould's ...

  8. Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings

    这场CF,脑子乱死啊...C题,搞了很长时间,结束了,才想到怎么做.B题,没看,D题,今天看了一下,很不错的组合题. 如果n和m都挺多的时候 以下情况都是变为1,根据偶数个0,最后将会为1,奇数个0, ...

  9. codechef Sums in a Triangle题解

    Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear ...

随机推荐

  1. 分布式事务(七)之Seata简介

    在前面的文章中,我们介绍了分布式事务的概念以及一些解决方案.fenSeata是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务.Seata将为用户提供了AT.TCC.SAGA和 ...

  2. vue 事件监听和es6模板语法

    es6模板语法的反引号是通过左上角的飘字符弄出来了,学废了吗?

  3. 最简单的Python3启动浏览器代码

    #encoding=utf-8 from selenium import webdriver import time from time import sleep   dr = webdriver.F ...

  4. Docker容器基础入门认知-网络篇

    这篇文章中,会从 docker 中的单机中的 netns 到 veth,再到单机多个容器之间的 bridge 网络交互,最后到跨主机容器之间的 nat 和 vxlan 通信过程,让大家对 docker ...

  5. 《手把手教你》系列技巧篇(四十五)-java+ selenium自动化测试-web页面定位toast-上篇(详解教程)

    1.简介 在使用appium写app自动化的时候介绍toast的相关元素的定位,在Web UI测试过程中,也经常遇到一些toast,那么这个toast我们这边如何进行测试呢?今天宏哥就分两篇介绍一下. ...

  6. Peaks Gym 100365H

    Peaks ( Gym 100365H ) 这题nk做法还挺正常的..后面那个循环就很恶心了 考虑 dp[i][j] 表示长度为i的排列,恰好有k个峰的方案数量. 然后转移就是把 i 插入 i-1 的 ...

  7. 关于基因GO分析的DAVID简单使用

    利用DAVID简单的进行GO富集度分析(这里只做简单的分析,即看基因是否存在在GO的三个过程里面) 比如我们有一组要分析的基因:TRPV6    CXADR    PROM1    GRAMD2   ...

  8. python爬虫之正则表达式(用在其他地方也可)

    1. 常用的匹配规则 ### 常用的匹配规则 # \w 匹配字母.数字及下划线 # \W 匹配不是字母.数字及下划线的字符 # \s 匹配任意空白字符,等价于[\t\n\t\f] # \S 匹配任意非 ...

  9. 使用Postman轻松实现接口数据关联

    Postman Postman是一款非常流行的HTTP(s)接口测试工具,入门简单,界面美观,功能强大.作为一个测试/开发工程师,这是一款必须要会用的工具.今天以一个实际的案例,来介绍下Postman ...

  10. tensoboard [Errno 22] Invalid argument 以及 Invalid format string问题解决

    Invalid argument 问题解决: 需要保证tensorboard与tensorflow版本一致. Invalid format string 问题解决: 修改 manager.py 文件中 ...