CodeForces 304A Pythagorean Theorem II 【基础】【暴力】
来源:互联网 发布:美国歌手prince 知乎 编辑:程序博客网 时间:2024/05/22 10:42
Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation:
where c represents the length of the hypotenuse, anda andb represent the lengths of the other two sides.
Given n, your task is to count how many right-angled triangles with side-lengthsa,b andc that satisfied an inequality1 ≤ a ≤ b ≤ c ≤ n.
The only line contains one integer n (1 ≤ n ≤ 104) as we mentioned above.
Print a single integer — the answer to the problem.
5
1
74
35
题意就是给你一个数n,让你判断三边边长均<=n的直角三角形有多少个
开始是想找规律的,但是找了好久都没发现,最后决定暴力试一下,然后AC了。
AC代码:
#include <cstdlib>#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;int main(){ int n, ans; while(~scanf("%d",&n)) { ans = 0; for(int i = 1; i <= n; ++i) for(int j = i; j <= n; ++j) { int tem = i * i + j * j; int tem1 = (sqrt(tem) + 0.5); if((tem1 * tem1 == tem) && (tem1 <= n) && ((i + j) > tem1)) { //cout<<tem1<<endl; ans++; //cout<<"i="<<i<<" j="<<j<<" tem="<<tem<<endl; } } cout << ans << endl; } return 0;}
- CodeForces 304A Pythagorean Theorem II 【基础】【暴力】
- codeforces 304A. Pythagorean Theorem II
- CodeForces 304A Pythagorean Theorem II
- A. Pythagorean Theorem II
- A. Pythagorean Theorem II
- coderforce 304a - Pythagorean Theorem II
- cf 304A Pythagorean Theorem II
- CF 304A(Pythagorean Theorem II-n内勾股数)
- codeforces 183(div2) A. Pythagorean Theorem II 枚举+二分查找
- Problem F Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II
- Pythagorean Theorem II
- Pythagorean Theorem II
- A. Pythagorean Theorem II(血的教训)
- CodeForces 199A Hexadecimal's theorem
- CodeForces 13A【暴力】
- Codeforces 485 A. Factory 暴力
- Codeforces 398A Cards 暴力
- codeforces 577A(暴力枚举)
- 进程与线程
- NavMesh.SamplePosition 采样位置 How to get a random point on NavMesh?
- 基本数据类型
- POJ1502MPI Maelstrom 【Dijkstra】
- 初次接触Android Studio发现并解决的一些问题
- CodeForces 304A Pythagorean Theorem II 【基础】【暴力】
- 前端工程师面试题
- 主板知识详解:支持内存类型
- 关于Object被Destroy之后,该Object的原引用==null的问题
- 求n!中某个因子个数【模板】
- Python技巧(二)字符串
- Python学习笔记
- 微信小程序之如何注册微信小程序
- Unity 与 NGUI 坐标转换原理