CF336A Vasily the Bear and Triangle 题解
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 题解的更多相关文章
- Codeforces Round #195 (Div. 2) A. Vasily the Bear and Triangle
水题,注意数据范围即可 #include <iostream> #include <algorithm> #include <utility> using name ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- cf A. Vasily the Bear and Triangle
http://codeforces.com/contest/336/problem/A #include <cstdio> #include <cstring> #includ ...
- codeforces 336D Vasily the Bear and Beautiful Strings(组合数学)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Vasily the Bear and Beautiful Strings Vas ...
- codeforces 336C Vasily the Bear and Sequence(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Vasily the Bear and Sequence Vasily the b ...
- 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 ...
- ZOJ 4081 Little Sub and Pascal's Triangle 题解
ZOJ 4081 Little Sub and Pascal's Triangle 题解 题意 求杨辉三角第n行(从1开始计数)有几个奇数. 考察的其实是杨辉--帕斯卡三角的性质,或者说Gould's ...
- Codeforces Round #195 (Div. 2) D题Vasily the Bear and Beautiful Strings
这场CF,脑子乱死啊...C题,搞了很长时间,结束了,才想到怎么做.B题,没看,D题,今天看了一下,很不错的组合题. 如果n和m都挺多的时候 以下情况都是变为1,根据偶数个0,最后将会为1,奇数个0, ...
- codechef Sums in a Triangle题解
Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear ...
随机推荐
- docker创建mongodb并且测试代码
mongodb docker 安装mongodb-创建用户 docker run -itd --name mongo -p 27017:27017 mongo --auth 进入数据库添加密码 ...
- 由于vue的for循环id并不严谨,提高id严谨性
如果后台没有传入id,我们拿到的数据没有id修改等操作不方便,如何拿到id呢 https://github.com/dylang/shortid 提供唯一id 插件的引入和使用: <templa ...
- CF1444C Team-Building
考虑我们判定二分图染色的经典算法: 染色. 我们把所有不同颜色块之间的边都保存下来. 只在图中保留相同颜块之间的边,并对其染色. 我们考虑记\(g_i\)为一个点的所在联通块编号,\(f_i\)为他在 ...
- Codeforces 453E - Little Pony and Lord Tirek(二维线段树+ODT)
Codeforces 题目传送门 & 洛谷题目传送门 一道难度 *3100 的 DS,而且被我自己搞出来了! 不过我终究还是技不如人,因为这是一个 \(n\log^2n\) + 大常数的辣鸡做 ...
- Python如何支持读入gz压缩或未压缩文件?
目录 需求 示例代码 笨办法 Pythonic方法 需求 要写一个接口,同时支持压缩和未压缩文件读入 示例代码 笨办法 import os import gzip filename = sys.arg ...
- mingling
mysql> USE mon Reading table information for completion of table and column names You can turn of ...
- oracle 将电话号码中间4位数以星号*代替
select replace('17665312355',substr('17665312355',4,4),'****') as phone, #类似E ...
- 分布式事务(3)---强一致性分布式事务Atomikos实战
分布式事务(1)-理论基础 分布式事务(2)---强一致性分布式事务解决方案 分布式事务(4)---最终一致性方案之TCC 前面介绍强一致性分布式解决方案,这里用Atomikos框架写一个实战的dem ...
- MySQL全面瓦解29:使用Partition功能实现水平分区
1 回顾 上一节我们详细讲解了如何对数据库进行分区操作,包括了 垂直拆分(Scale Up 纵向扩展)和 水平拆分(Scale Out 横向扩展) ,同时简要整理了水平分区的几种策略,现在来回顾一下. ...
- 零基础学习java------day7------面向对象
1. 面向对象 1.1 概述 面向过程:c语言 面向对象:java :python:C++等等 面向对象的概念: (万物皆对象)------think in java everything in ...