文章

75

粉丝

66

获赞

75

访问

6.7k

头像
博学楼的阶梯(模拟 思路清晰易懂 附注释) 题解:
P1005 计算机考研机试入门题
发布于2024年5月2日 00:29
阅读数 105

 优化了内存,没有开数组

#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;
} 

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发