poj 1543 & HDU 1334 & ZOJ 1331 Perfect Cubes(数学 暴力大法好)

题目链接:http://poj.org/problem?id=1543

Description

For hundreds of years Fermat‘s Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c^n, has remained elusively unproven. (A recent proof is believed to be correct, though it is still undergoing scrutiny.)
It is possible, however, to find integers greater than 1 that satisfy the "perfect cube" equation a^3 = b^3 + c^3 + d^3 (e.g. a quick calculation will show that the equation 12^3 = 6^3 + 8^3 + 10^3 is indeed true). This problem requires that you write a program
to find all sets of numbers {a,b,c,d} which satisfy this equation for a <= N.

Input

One integer N (N <= 100).

Output

The output should be listed as shown below, one perfect cube per line, in non-decreasing order of a (i.e. the lines should be sorted by their a values). The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist
several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.

Sample Input

24

Sample Output

Cube = 6, Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
Cube = 18, Triple = (9,12,15)
Cube = 19, Triple = (3,10,18)
Cube = 20, Triple = (7,14,17)
Cube = 24, Triple = (12,16,20)

Source

Mid-Central USA 1995

题目链接:

寻找:a^3 = b^3 + c^3 + d^3 。

代码如下:(POJ)

#include <cstdio>
#include <cstring>
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 3; i <= n; i++)
        {
            for(int j = 2; j < n; j++)
            {
                for(int k = j+1; k < n; k++)
                {
                    for(int l = k+1; l < n; l++)
                    {
                        if(i*i*i==j*j*j+k*k*k+l*l*l)
                            printf("Cube = %d, Triple = (%d,%d,%d)\n",i,j,k,l);
                    }
                }
            }
        }
    }
    return 0;
}

(HDU & ZOJ)

#include <cstdio>
#include <cstring>
int main()
{
    for(int i = 3; i <= 200; i++)
    {
        for(int j = 2; j < 200; j++)
        {
            for(int k = j+1; k < 200; k++)
            {
                for(int l = k+1; l < 200; l++)
                {
                    if(i*i*i==j*j*j+k*k*k+l*l*l)
                        printf("Cube = %d, Triple = (%d,%d,%d)\n",i,j,k,l);
                }
            }
        }
    }
}
时间: 2024-10-29 19:12:04

poj 1543 & HDU 1334 & ZOJ 1331 Perfect Cubes(数学 暴力大法好)的相关文章

POJ 1071 &amp; HDU 1364 &amp; ZOJ 1019 Illusive Chase(DFS)

题目链接: POJ:http://poj.org/problem?id=1071 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1364 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=19 Description Tom the robocat is presented in a Robotics Exhibition for an enthusiastic audien

POJ 2062 HDU 1528 ZOJ 2223 Card Game Cheater

水题,感觉和田忌赛马差不多 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; struct P1 { int Num; int Hua; } Play1[30]; struct P2 { int Num; int Hua; } Play2[30]; bool cmp1(const P1&a,const P1&b

uva 10129 poj 1386 hdu 1116 zoj 2016 play on words

//本来是想练一下欧拉回路的,结果紫书上那题是大水题!!!!! 题意:给出n个单词,是否可以把单词排列成每个单词的第一个字母和上一个单词的最后一个字母相同 解:欧拉通路存在=底图联通+初度!=入度的点至多只有两个(分别为入点和出点) 1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #inclu

HDU 2058 The sum problem (数学+暴力)

题意:给定一个N和M,N表示从1到N的连续序列,让你求在1到N这个序列中连续子序列的和为M的子序列区间. 析:很明显最直接的方法就是暴力,可是不幸的是,由于N,M太大了,肯定会TLE的.所以我们就想能不能优化一下,找一个范围.想到这是一个连续的序列而且是从1开始的,这不就是一个等差数列么,公差是1罢了.由求和公式得Sn = (a1+an) * n / 2;所以说n最大就是sqrt(M*2)(想一想为什么),因为a1+an 一定是大于n的.如果我们取区间的和,那么Sn = (ai+aj) * (j

poj 1543 Perfect Cubes (暴搜)

Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15302   Accepted: 7936 Description For hundreds of years Fermat's Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c

杭电 HDU ACM 1334 Perfect Cubes

Perfect Cubes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2413    Accepted Submission(s): 1061 Problem Description For hundreds of years Fermat's Last Theorem, which stated simply that for

POJ1607 &amp; HDU 1330 &amp; ZOJ 1216 Deck(数学题)

题目链接: POJ  1607 : http://poj.org/problem?id=1607 HDU 1330 :http://acm.hdu.edu.cn/showproblem.php?pid=1330 ZOJ  1216 : Description A single playing card can be placed on a table, carefully, so that the short edges of the card are parallel to the table

POJ 1113 || HDU 1348: wall(凸包问题)

传送门: POJ:点击打开链接 HDU:点击打开链接 下面是POJ上的题: Wall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29121   Accepted: 9746 Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's cast

POJ 2411 &amp;&amp; HDU 1400 Mondriaan&#39;s Dream (状压dp 经典题)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12341   Accepted: 7204 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series