2024.12.26 周四
2024.12.26 周四
Q1. 1100
There is a ribbon divided into
Monocarp plays a game with a chip. The game consists of several turns. During the first turn, Monocarp places the chip in the
- move the chip to the next cell (i. e. if the chip is in the cell
, it is moved to the cell ). This action is impossible if the chip is in the last cell; - choose any cell
and teleport the chip into that cell. It is possible to choose the cell where the chip is currently located.
At the end of each turn, the integer written in the cell with the chip is increased by
Monocarp's goal is to make some turns so that the
Help Monocarp calculate the minimum number of times he has to teleport the chip.
------------------------独自思考分割线------------------------
-
思维与观察,递推思想,是有趣的题..
A1.
- 本质就是在求在一个全
数组中不断对其连续子串加 至少加多少次才能变成指定数组。 - 观察/递推思维:在全局寻找答案比较难时考虑从开始递推寻找答案。如果画出以下图定会助力思考。
- 出了2个假思路,第三次基本正确比正解复杂点且不知道wa哪里了。
------------------------代码分割线------------------------
A1.
#include <bits/stdc++.h>
#define int long long //
#define endl '\n' // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(6);
int T = 1;
cin >> T;
while (T--)
_();
return 0;
}
void _()
{
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int res = -1;
for (int i = 1; i <= n; i++)
res += a[i] > a[i - 1] ? a[i] - a[i - 1] : 0;
cout << res << endl;
}
// void _()
// {
// int n;
// cin >> n;
// vector<int> a(n + 2);
// int cnt = 0;
// for (int i = 1; i <= n; i++)
// {
// int x;
// cin >> x;
// if (i == 1 || x - a[i - 1])
// a[++cnt] = x;
// }
// n = cnt;
// map<int, int> has;
// for (int i = 1; i <= n; i++)
// if (a[i] > a[i - 1] && a[i] > a[i + 1])
// has[a[i]]--;
// else if (a[i] < a[i - 1] && a[i] < a[i + 1])
// has[a[i]]++;
// cnt = 1;
// int last = 0, res = 0;
// for (auto [x, val] : has)
// {
// res += (x - last) * cnt;
// last = x;
// cnt += val;
// }
// res--;
// cout << res << endl;
// }
// void _()
// {
// int n;
// cin >> n;
// vector<vector<int>> vec;
// vector<int> a(n + 1);
// for (int i = 1; i <= n; i++)
// cin >> a[i];
// for (int i = 1; i <= n; i++)
// if (a[i])
// {
// vector<int> t;
// int j = i;
// for (; j <= n && a[j]; j++)
// t.push_back(a[j]);
// i = j - 1;
// vec.push_back(t);
// }
// // bug(vec.size());
// int res = vec.size() - 1;
// for (auto a : vec)
// {
// sort(a.rbegin(), a.rend());
// res += a[0] - 1;
// }
// cout << res << endl;
// }
// void _()
// {
// int n;
// cin >> n;
// int res = 0;
// int cnt = 0, maxw = 0;
// for (int i = 0; i < n; i++)
// {
// int x;
// cin >> x;
// if (x)
// cnt++, maxw = max(maxw, x);
// else
// {
// if (cnt)
// {
// res++;
// res += maxw - 1;
// cnt = 0;
// maxw = 0;
// }
// }
// }
// if (cnt)
// {
// res += maxw - 1;
// cnt = 0;
// maxw = 0;
// }
// cout << res << endl;
// }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!