codeforces707C:Pythagorean Triples】的更多相关文章

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…
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…
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 appeared, that…
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…
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…
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 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…
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 appeared, t…
题意:给定一个数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> #…
题目链接: 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)=…
数学,构造. 这题比较有意思,一开始没发现结论写了一个最坏复杂度为$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}$.…
题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素数x作为直角边,那么另外两条边的长度一定为(x * x - 1)/2和(x * x + 1)/2,因此对于每个数我们只需要找到n的最小素因子(除2外)即可,需要额外处理一下2的幂次. 代码实现如下: #include <set> #include <map> #include <…
题目链接: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的奇…
一边长为a的直角三角形,a^2=c^2-b^2.可以发现1.4.9.16.25依次差3.5.7.9...,所以任何一条长度为奇数的边a,a^2还是奇数,那么c=a^2/2,b=c+1.我们还可以发现,1.4.9.16.25.36各项差为8.12.16.20,偶数的平方是4的倍数,那么c=a^2/4-1,b=a^2/4+1. #include <iostream> using namespace std; int main() { long long n; cin>>n; n*=n;…
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小; [题解] 首先明确n<=2的时候是无解的. n>2之后都有解; 这里设 n2+b2=a2 则有 n2=a2−b2 也即 n2=(a+b)∗(a−b) 这里对n分两类讨论; ① n为奇数 则令 a−b=1 a+b=n2 这样 2∗a=n2+1 因为n是奇数所以右边是个偶数; 得出来的a就是整数了…
Pythagorean Triples CodeForces - 707C 悉宇大大最近在学习三角形和勾股定理.很显然,你可以用三个边长为正数的线段去构造一个直角三角形,而这三个数被称作“勾股数”. 比如,(3,4,5),(5,12,13),(6,8,10)都是勾股数. 现在悉宇大大很好奇如果他能够确定直角三角形的某一条边,那么他能否找到另外两条边使得这三条边组成直角三角形.注意,他所确定的边可以是直角边也可以是斜边. 悉宇大大能够轻松的解决这个问题,你也可以吗? Input 输入一个整数n(1…
此题是 2018 年 ICPC Asia Beijing Regional Contest 的 C 题. 题目大意 求斜边长度不超过 $n$($ n \le 10^9$) 的勾股数的数量.不计两直角边的顺序,即勾股数 (a, b, c) 和 (b, a, c) 视作同一组. 分析 这是一道颇为经典的计数问题. 请先阅读维基百科上的 Pythagorean triple 条目. 设斜边为 $n$ 的勾股数有 $f(n)$ 个.又设斜边为 $n$ 的本原勾股数有 $g(n)$ 个.于是有 $ f(n…
两道C题题解,能推出来公式简直是无敌. http://codeforces.com/problemset/problem/707/C codeforces707C. Pythagorean Triples 这个题就是直角三角形的三条边,给你一条边的长度,让你输出其他两边的长度. 会发现有规律.当数为奇数时,就是平方除以2,然后另一边再加上1就可以. 偶数的时候一直除以2,直到4为止,然后特判就可以,再用一下快速幂就可以了. 代码: #include<iostream> #include<…
LINK:Perfect Triples 初看这道题 一脸懵逼.. 完全没有思路 最多就只是发现一点小规律 即. a<b<c. 且b的最大的二进制位一定严格大于a b的最大二进制位一定等于c. 但是这对解题没有任何用处. 考虑打个表看看有什么规律没有. 通过这道题 我承认 打表找规律也是一个技术活. 虽然能看出来到了第二排 a的数值是递增的 考虑特判前面几个我们就能快速找到a了. 但是b 和 c还是难找.那继续观察后面几项的规律. 我的败笔也是出自这里 规律一般也是符合较小的数据的 没道理不符…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
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…
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpo…
题目链接:http://codeforces.com/contest/707/problem/A A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Small, but very brave, mouse Brain was not accepted to summer school of y…
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 appeared, t…
链接 1.括号序列贪心/CF&51nod原题 [分析]: 贪心,每次到i的时候,假如你要在i里面要卖掉股票,获益是a[i], 肯定要在前面要么:1)把已经卖了的变成不买不卖,需要-a[j], 2)把已经不买不卖的变成买,需要-a[j] [原题链接]:CF&E CF&D 51nod高卖低买 3.构造/封闭运算/费马小定理下模意义/重新定义+和 * [题意]: 输入:素数p 要求构造规则a[p*p],使其满足:(m+n)^p=m^p+n^p a的含义: a[i][j] = (i-1)…
A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpo…
2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fallen Lord(sort(a+1,a+1+n,greater<int>()); 真好用) P4161 [SCOI2009]游戏 P1707 刷题比赛 2021-10-12 CF1573A Countdown P2717 寒假作业 P7868 [COCI2015-2016#2] VUDU P1660…
The Hundred Greatest Theorems The millenium seemed to spur a lot of people to compile "Top 100" or "Best 100" lists of many things, including movies (by the American Film Institute) and books (by the Modern Library). Mathematicians wer…
A Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the fi…
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知Internet的目的是让各个net交互.所以,Internet实质上是将世界上各个国家.各个网络运营商的多个网络相互连接构成的一个全球范围内的统一网,使各个网络之间能够相互到达.各个国家和运营商构建网络采用的底层技术和实现可能各不相同,但只要采用统一的上层协议(TCP/IP)就可以通过Internet…