UVa12032 - The Monkey and the Oiled Bamboo(贪心)

简介: UVa12032 - The Monkey and the Oiled Bamboo(贪心)
#include <cstdio>#include <algorithm>usingnamespacestd;
constintN=100005;
intr[N], a[N];
intn;
boolinput();
intsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif // ONLINE_JUDGEintt;
scanf("%d", &t);
for (inti=1; i<=t; i++) {
input();
intans=solve();
printf("Case %d: %d\n", i, ans);
    }
return0;
}
boolinput()
{
scanf("%d", &n);
r[0] =0;
for (inti=1; i<=n; i++) {
scanf("%d", &r[i]);
    }
}
intsolve()
{
for (inti=0; i<n; i++) {
a[i] =r[i+1] -r[i];
    }
intans=-1;
for (inti=n-1; i>=0; i--) {
if (ans==a[i]) ans++;
ans=max(ans, a[i]);
    }
returnans;
}
目录
相关文章
|
9月前
UVa668 - Parliament(贪心)
UVa668 - Parliament(贪心)
31 0
|
9月前
UVa11420 - Chest of Drawers(动态规划)
UVa11420 - Chest of Drawers(动态规划)
31 0
|
9月前
UVa10596 - Morning Walk(并查集)
UVa10596 - Morning Walk(并查集)
38 0
|
算法 安全 C++
【牛客刷题-算法】NC32 求平方根 (又是辛苦debug的一天)
【牛客刷题-算法】NC32 求平方根 (又是辛苦debug的一天)
109 0
【牛客刷题-算法】NC32 求平方根 (又是辛苦debug的一天)
|
算法 C语言 C++
【牛客-算法】NC38 螺旋矩阵
【牛客-算法】NC38 螺旋矩阵
75 0
【牛客-算法】NC38 螺旋矩阵
|
算法 C语言
【牛客刷题-算法】NC103 反转字符串
【牛客刷题-算法】NC103 反转字符串
62 0
【牛客刷题-算法】NC103 反转字符串
HDU 3506 Monkey Party(动态规划)
HDU 3506 Monkey Party(动态规划)
46 0
HDU 3506 Monkey Party(动态规划)
|
人工智能 Java
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
Jumping Monkey Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 747 Accepted Submission(s): 360
188 0
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
UVa 11292 - Dragon of Loowater(排序贪心)
UVa 11292 - Dragon of Loowater(排序贪心)
76 0
|
Java BI 机器学习/深度学习