暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

题目传送门

 1 /*
 2     暴力:O (n^2)
 3 */
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <vector>
 9 using namespace std;
10
11 const int MAXN = 1e4 + 10;
12 const int INF = 0x3f3f3f3f;
13
14 int main(void)        //Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II
15 {
16     int n;
17     while (scanf ("%d", &n) == 1)
18     {
19         int ans = 0;
20         for (int i=1; i<=n; ++i)
21         {
22             for (int j=i; j<=n; ++j)
23             {
24                 if (i * i + j * j > n * n)    break;
25                 int c = sqrt (i * i + j * j);
26                 if (c <= n && c * c == i * i + j * j)    ans++;
27             }
28         }
29
30         printf ("%d\n", ans);
31     }
32
33     return 0;
34 }
时间: 2024-11-05 14:55:58

暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II的相关文章

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

题目传送门 1 /* 2 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 5e2 + 10; 12 const int

数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

题目传送门 1 /* 2 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 3 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 4 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #in

构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

题目传送门 1 /* 2 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! 3 */ 4 /************************************************ 5 Author :Running_Time 6 Created Time :2015-8-3 8:43:02 7 File Name :A.cpp 8 *************************************************/ 9 1

二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 5e2 + 10; 10 const int MAXM = 1e6 + 10; 11 const int INF = 0

Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

给定一个直角三角形的一边长度.问是否存在一个直角三角形,使得它满足有一边的长度是x 当x=1.2的时候是无解的,可以暴力打表看看. 注意到,相邻的两个数的平方的差值是奇数 x^2 - (x-1)^2 = 2*x-1 间隔为2的两个数的平方的差值是偶数 (x+1)^2 - (x-1)^2 = 4*x 这样就可以分类讨论了. 把n永远当成是指角边就OK #include <cstdio> #include <cstdlib> #include <cstring> #incl

Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 并查集求奇偶元环

D. Dividing Kingdom II Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves. The

Codeforces Round #224 (Div. 2) D 暴力搜索加记忆化

题意读了半年,英语太渣,题意是摆两个棋子在棋盘上作为起点,但是起点不能在#上,然后按照图的指示开始走, < 左 > 右 ^上 v下,走的时候只能按照图的指示走,如果前方是 #的话,可以走进去,但是 走进去之后便不能再走了,走的途中两个棋子不能相碰,但是最终都走到同一个#里是没事的,并且若是能走 无限步的话 输出 -1, 例如  > < 这样左右左右的走就能无限走,然后问你 两个棋子走的最大步数的和 一开始被输出-1给困住了,因为除了 .> <这样以外  还可以刚好形成一

Codeforces Round #422 (Div. 2) A. I&#39;m bored with life 暴力

A. I'm bored with life Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the