专栏文章

题解:P11061 【MX-X4-T1】「Jason-1」IO++

P11061题解参与者 4已保存评论 3

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
3 条
当前快照
1 份
快照标识符
@minrzrtf
此快照首次捕获于
2025/12/02 07:23
3 个月前
此快照最后确认于
2025/12/02 07:23
3 个月前
查看原文
显然,不能去掉输出语句。而输出语句使用的输入必须要被输入。如果一个数被输入,那么这个数前面的数必须输入。为了最小化语句个数,只保留需要用到的输入语句和输出语句。根据上述分析,输入语句可以统计为输出语句使用的最大值。所以,输出语句使用的最大的输入的数加上输出语句的个数即为最终的答案。
CPP
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, x, maxi, ans; // maxi 统计输出语句使用的最大值,ans 统计输出语句的个数
void solve()
{
    cin >> n;
    while (n--)
    {
        cin >> x;
        if (x)
        {
            maxi = max(maxi, x);
            ans++;
        }
    }
    cout << maxi + ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

评论

3 条评论,欢迎与作者交流。

正在加载评论...