文章

3

粉丝

118

获赞

0

访问

22

头像
博学楼的阶梯 题解:
P1005 计算机考研机试入门题
发布于2025年3月11日 21:43
阅读数 9

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

int a[105];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	cin >> t;
	a[0] = 1;
	while(t--){
		cin >> n;
		for(int i = 1; i <= n; i++) cin >> a[i];
		int ans = 0;
		for(int i = 0; i < n; i++){
			if(a[i] < a[i + 1]) ans += (a[i + 1] - a[i]) * 6;
			else if(a[i] > a[i + 1]) ans += (a[i] - a[i + 1]) * 4;
			else ans += 3;
			ans += 3;
		}
		cout << ans << endl;
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发