文章

21

粉丝

0

获赞

19

访问

4.8k

头像
最大数组距离 题解:
P5382 四川大学2025年机试题
发布于2026年3月27日 16:17
阅读数 185

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<vector<int>> matrix;
	// 输入
	for(int i = 0; i < n; i++){
		int size;
		cin >> size;
		vector<int> tmp;
		// tmp.clear(); // 
		tmp.resize(size);
		for(int j = 0; j < size; j++){
			cin >> tmp[j];
		}
		matrix.push_back(tmp);
	}
	//-----------------------------
	
	int ans = 0;
	for(int i = 0; i < n; i++){
		int low, high;
		low = matrix[i][0];
		high = matrix[i][matrix[i].size() - 1];
		for(int j = i + 1; j < n; j++){
			ans = max(ans, abs(low - matrix[j][matrix[j].size() - 1]));
			ans = max(ans, abs(high - matrix[j][0]));
		}
	}
	
	cout << ans << endl;
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发