欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

有一个长为n的数组A,求满足0≤a≤bn的A[b]-A[a]的最大值。 给定数组A及它的大小n,请返回最大差值。...

发布时间:2023/11/29 编程问答 76 豆豆
生活随笔 收集整理的这篇文章主要介绍了 有一个长为n的数组A,求满足0≤a≤bn的A[b]-A[a]的最大值。 给定数组A及它的大小n,请返回最大差值。... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h" #include <iostream> #include <vector> #include <list> #include <deque> #include <string> #include <algorithm> using namespace std;class LongestDistance { public:int getDis(vector<int> A, int n) {int max = 0;for (int i = 0;i < n;i++){for (int j = i + 1;j < n;j++){if (max < (A[j] - A[i])){max = A[j] - A[i];}}}return max;} }; int main() {LongestDistance ld;vector<int> A = { 10,5 };cout << ld.getDis(A,2) << endl;return 0; };

转载于:https://www.cnblogs.com/wdan2016/p/6442833.html

总结

以上是生活随笔为你收集整理的有一个长为n的数组A,求满足0≤a≤bn的A[b]-A[a]的最大值。 给定数组A及它的大小n,请返回最大差值。...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。