文章
117
粉丝
69
获赞
886
访问
143.6k
优化了内存,没有开数组
#include <bits/stdc++.h>
using namespace std;
int T;
int main()
{
	cin >> T;
	
	while(T --)
	{
		int n;
		cin >> n;
		
		int last = 1, ans = 0; //last记录上一层状态,ans统计答案 
		for(int i = 0; i < n; i ++)
		{
			int x; cin >> x;  //x为当前第几层 
			//模拟到达每层所需的时间 
			if(x == last) ans += 3;
			else if(x > last) ans += (x - last) * 6;
			else ans += (last - x) * 4;
			 
			ans += 3; //每层停留的时间 
			
			last = x; //更新状态 
		}
		
		cout << ans << endl;
	}
	
	return 0;
} 
登录后发布评论
暂无评论,来抢沙发