题目链接:http://codeforces.com/contest/707/problem/C 题目大意:给你一条边,问你能否构造一个包含这条边的直角三角形且该直角三角形三条边都为整数,能则输出另外两条边,否则输出-1“”. 解题思路:下面是我从作业帮上找的- -, 利用平方差公式令斜边为c,直角边为a.b,且b为最短边c²-a²=(c+a)(c-a)因此(c+a)(c-a)是完全平方数,且(c-a)是(c+a)的一个因数1.如果(c-a)=1,则(c+a)是完全平方数(最短边是任意大于2的奇…
数学,构造. 这题比较有意思,一开始没发现结论写了一个最坏复杂度为$O({10^9})$暴力居然能$AC$,正因为如此,我才发现了规律. 一开始是这么想的: 先假设$n$为直角边,设斜边长度为$c$,另一条直角边长度为$b$,因此有${c^2} - {b^2} = {n^2}$. 左边因式分解得到:$(c + b)(c - b) = {n^2}$.我们记$A = c + b$,$B=c-b$.那么:$c = \frac{{A + B}}{2}$,$b = \frac{{A - B}}{2}$.…
题目链接: http://codeforces.com/problemset/problem/707/C 题目大意: 给你一个数,构造其余两个勾股数.任意一组答案即可,没法构造输出-1. 答案long long 范围. 题目思路: [数学] 这里贴一下勾股数的构造: 当a为大于1的奇数2n+1时,b=2n2+2n, c=2n2+2n+1. 实际上就是把a的平方数拆成两个连续自然数,例如: n=1时(a,b,c)=(3,4,5) n=2时(a,b,c)=(5,12,13) n=3时(a,b,c)=…
题意:给定一个数n,问你其他两边,能够组成直角三角形. 析:这是一个数论题. 如果 n 是奇数,那么那两边就是 (n*n-1)/2 和 (n*n+1)/2. 如果 n 是偶数,那么那两边就是 (n/2*n/2-1) 和 (n/2*n/2+1).那么剩下的就很简单了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #…
两道C题题解,能推出来公式简直是无敌. http://codeforces.com/problemset/problem/707/C codeforces707C. Pythagorean Triples 这个题就是直角三角形的三条边,给你一条边的长度,让你输出其他两边的长度. 会发现有规律.当数为奇数时,就是平方除以2,然后另一边再加上1就可以. 偶数的时候一直除以2,直到4为止,然后特判就可以,再用一下快速幂就可以了. 代码: #include<iostream> #include<…
题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appea…
Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such th…
Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresp…
C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers…
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to tr…