日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

2.1基本算法之枚举_1812完美立方

發布時間:2025/3/15 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2.1基本算法之枚举_1812完美立方 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://noi.openjudge.cn/ch0201/1812/

C++代碼來源于以下鏈接

https://blog.csdn.net/qq_26919935/article/details/77905491

https://blog.csdn.net/xcdq_aaa/article/details/112630852

/* 1812完美立方(2.1基本算法之枚舉) 2.1基本算法之枚舉_1812完美立方 https://blog.csdn.net/qq_26919935/article/details/77905491 http://noi.openjudge.cn/ch0201/1812/ */ #include <iostream> #include<stdio.h> using namespace std; //http://noi.openjudge.cn/ch0201/1812/ //4重循環,關鍵是該break的時候盡早,省了很多無用功 int n,a,b,c,d,a3,b3,c3,d3; int main(int argc, char *argv[]) {cin>>n;for(int a=2;a<=n;a++){a3=a*a*a;for(int b=2;b<=n;b++){b3=b*b*b;if(b3>=a3)break;for(int c=b;c<=n;c++){c3=c*c*c;if(c3+b3>=a3)break;for(int d=c;d<=n;d++){d3=d*d*d;if(d3+c3+b3>a3)break;if(d3+c3+b3==a3){printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);}}}}}return 0; }
/* 2.1基本算法之枚舉_1812完美立方 方法二 http://noi.openjudge.cn/ch0201/1812/https://blog.csdn.net/qq_26919935/article/details/77905491 https://blog.csdn.net/xcdq_aaa/article/details/112630852 */ #include <iostream> using namespace std; int all[20]; int main() {int n;cin >> n;for (int i = 2; i <= n; i++) {for (int j = 2; j <= n; j++) {for (int k = j; k <= n; k++) {for (int l = k; l <= n; l++) {if (i * i * i == j * j * j + k * k * k + l * l * l) {cout << "Cube = " << i << ", Triple = (" << j << ","<< k << "," << l << ")" << endl;}}}}} }

?

?

?

?

?


?

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的2.1基本算法之枚举_1812完美立方的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。