CodeForces 707C Pythagorean Triples(数学 构造)
来源:互联网 发布:市濑秀和知乎 编辑:程序博客网 时间:2024/05/21 09:10
题意:给出直角三角形一边,求另两边,如果存在输出任意一组即可。
点击打开链接
【分析】
对于直角三角形△ABC,如图:
我们知道的是
因为题目说如果题目存在多种解,输出任何一个就可以了,所以我们不妨假设输入的n是一条直角边的长度,那么
根据平方差公式可得
那么,这个时候,我们要求解的就是a,b
于是乎,我们分类讨论即可
#include<iostream>#include<cstdio>using namespace std;typedef long long ll;int main(void){ ll n; while(cin >> n) { if(n <= 1) puts("-1"); else { if(n%2) printf("%I64d %I64d\n", (n*n+1)/2-1, (n*n+1)/2); else printf("%I64d %I64d\n", (1+(n*n)/4)-, 1+(n*n)/4); } } return 0;}
0 0
- CodeForces 707C Pythagorean Triples(数学 构造)
- codeforces 707 C Pythagorean Triples【数学】
- Codeforces 707C Pythagorean Triples(数学)
- Codeforces Problem 707C Pythagorean Triples(数学)
- codeforces 707C Pythagorean Triples(数学)
- codeforces 707-C. Pythagorean Triples(数学)
- [codeforces] C - Pythagorean Triples 数学
- codeforces 707C - Pythagorean Triples
- codeforces 707C Pythagorean Triples
- 【codeforces 707C Pythagorean Triples】
- codeforces--707C. Pythagorean Triples
- CodeForces 707C-Pythagorean Triples
- 【数学相关、规律】Codeforces 707C Pythagorean Triples
- Codeforces Round #368-C - Pythagorean Triples-数学
- Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学构造)
- CodeForces 707C Pythagorean Triples(数学题)
- codeforces 707 c Pythagorean Triples 数论+勾股数
- codeforces C. Pythagorean Triples (【数学】毕达哥拉斯三元数组 勾股定理)
- MySQL常用指令(二)查询数据
- 数据结构之环形队列实现(1)
- 设计模式学习之适配器模式
- C++实现队列--数组实现和链表实现
- 1--百度2017春招笔试真题编程题集合--买帽子(Python)
- CodeForces 707C Pythagorean Triples(数学 构造)
- 问题: 使用putty登录显示network error:Connection refused使用putty登录显示network error:Connection refused 在局域网使
- 栈应用 一(括号匹配)
- 在eclipse中将android工程打包成apk
- 南阳oj 题目21 三个水杯
- 一些常用的第三方框架之ImageLoad
- 函数变量
- Spring加载resource时classpath*:与classpath:的区别
- Fork/Join框架