poj1543-Perfect Cubes(暴力)

水题:求n^3 =  a^3 + b^3 + c^3 ;暴力即可

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4     int n ;
 5     cin>>n;
 6     for(int i = 3 ; i <= n ; i++){
 7         for(int j = 2 ; j <= n ; j++){
 8             for(int k = j ; k <= n ; k++){
 9                 for(int l = k ; l <= n ; l++){
10                     if(i*i*i==j*j*j+k*k*k+l*l*l)
11                         printf("Cube = %d, Triple = (%d,%d,%d)\n",i,j,k,l);
12                 }
13             }
14         }
15     }
16     return 0;
17 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-10 08:13:19

poj1543-Perfect Cubes(暴力)的相关文章

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

poj 1543 &amp; HDU 1334 &amp; 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 believ

A. The Fault in Our Cubes 暴力dfs

http://codeforces.com/gym/101257/problem/A 把它固定在(0,0, 0)到(2, 2, 2)上,每次都暴力dfs检查,不会超时的,因为规定在这个空间上,一不行,就会早早退出. 这样写起来比较好写. #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <

UVaLive 3401 Colored Cubes (暴力)

题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostrea

(HDU)1334 -- Perfect Cubes (完美立方)

题目链接:http://vjudge.net/problem/HDU-1334 暴力枚举,我不知道我的优化是不是暴力里面最简单的... 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 #include <string> 7 #include <cstdlib>

POJ 1543 Perfect Cubes

Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14344   Accepted: 7524 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 remain

hdu 1334 Perfect Cubes

题目的意思是给出一个数N,寻找a,b,c,d使得a^3=b^3+c^3+d^3成立,其中a<=N,1<b<c<d. #include<cstdio> int main(){ int n,a,b,c,d; while(~scanf("%d",&n)){ for(a=6;a<=n;a++){//样例中a最小为6 for(b=2;b<a;b++){ for(c=b+1;c<a;c++){ for(d=c+1;d<a;d++)

HDU1334_Perfect Cubes【水题】

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