我是靠谱客的博主 舒心太阳,这篇文章主要介绍Codeforces Beta Round #11 A. Increasing Sequence 贪心,现在分享给大家,希望可以做个参考。

题目链接:这里
题意:你每次操作可以使得一个数增加d,问你最小操作多少次,可以使得这个序列变成一个递增序列
解法:直接贪心,能变就变。。。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//CF 11A #include <bits/stdc++.h> using namespace std; int a[2010]; int n, d; int main(){ scanf("%d%d", &n, &d); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); int ans = 0; for(int i = 1; i <= n; i++){ if(a[i] <= a[i-1]){ int temp = (a[i-1] - a[i] + d) / d; a[i] = a[i] + temp*d; ans += temp; } } cout << ans << endl; return 0; }

最后

以上就是舒心太阳最近收集整理的关于Codeforces Beta Round #11 A. Increasing Sequence 贪心的全部内容,更多相关Codeforces内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部