codeforces 304A. Pythagorean Theorem II

简介: 给你一个n,计算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc构成的三角形满足勾股定理,c为斜边。没有简单的方法,直接爆力,但是要注意,有些abc满足勾股定理的表达式,但不一定是三角形,所以要判断一下,根据三角形三边的性质,两边之和大于第三边,两边之差小于第三边。

给你一个n,计算出1 ≤ a ≤ b ≤ c ≤ n.使得由abc构成的三角形满足勾股定理,c为斜边。

没有简单的方法,直接爆力,但是要注意,有些abc满足勾股定理的表达式,但不一定是三角形,所以要判断一下,根据三角形三边的性质,两边之和大于第三边,两边之差小于第三边。

//cf304 A
//2013-06-05-18.14
#include <stdio.h>
#include <math.h>
int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        int cnt = 0;
        for (int i = 1; i < n; i++)
        {
            for (int j = 1; j < i; j++)
            {
                int t = i*i + j*j;
                int c = (int)sqrt(t);
                if (c > n)
                    continue;
                if (c*c != t)
                    continue;
                if (i+j > c && i+c > j && j+c > i && i-j < c && i-c < j && j-c < i)
                    cnt++;
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}
目录
相关文章
|
6月前
codeforces 322 B Ciel and Flowers
有红绿蓝三种颜色的画,每种拿三朵可以组成一束花,或者各拿一朵组成花束,告诉你每种花的数目,求出可能组成最多的花束。 如果你的代码过不了,考虑一下 8 8 9这种组合。 因为数据量很大,我的思想就是局部和总体采用不同的策略。
26 0
|
6月前
codeforces 312
A. Whose sentence is it?
26 0
|
6月前
codeforces 327 A Ciel and Dancing
给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1。 这里要注意很多细节 比如全为1,要求必须翻转,这时候我们只要翻转一个1就可以了,对于其他情况,我们只要计算区间里面如果0多于1,将其翻转后计算1的总数,然后取最大值。
20 0
|
6月前
codeforces 322 A Ciel and Dancing
有n个男孩和m个女孩,他们要结对跳舞,每对要有一个女孩和一个男孩,而且其中一个要求之前没有和其他人结对,求出最大可以结多少对。
21 0
C - Rumor CodeForces - 893C
C - Rumor CodeForces - 893C
62 0
|
人工智能
Codeforces 777C Alyona and Spreadsheet
C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard ...
1133 0
|
人工智能
Codeforces 719B Anatoly and Cockroaches
B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output:stan...
862 0