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;
}
目录
相关文章
|
3月前
【洛谷 P1219】[USACO1.5]八皇后 Checker Challenge 题解(深度优先搜索+回溯法)
**USACO1.5八皇后挑战**是关于在$n\times n$棋盘上放置棋子的,确保每行、每列及两条主对角线上各有一个且仅有一个棋子。给定$6$作为输入,输出前$3$个解及解的总数。例如,对于$6\times6$棋盘,正确输出应包括解的序列和总数。代码使用DFS解决,通过跟踪对角线占用状态避免冲突。当找到所有解时,显示前三个并计数。样例输入$6$产生输出为解的前三个排列和总数$4$。
25 0
UVa668 - Parliament(贪心)
UVa668 - Parliament(贪心)
48 0
HDU 3506 Monkey Party(动态规划)
HDU 3506 Monkey Party(动态规划)
56 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
214 0
[HDU 7136] Jumping Monkey | 并查集 | 逆向思维
UVa 11292 - Dragon of Loowater(排序贪心)
UVa 11292 - Dragon of Loowater(排序贪心)
90 0
|
Java BI 机器学习/深度学习
Uva 10339 - Watching Watches【数论,暴力】
题目链接:10339 - Watching Watches 题意:两个时钟,一个每天慢a秒,一个每天慢b秒,问两钟重新相遇的时刻 1圈有12 * 60 * 60秒,然后1圈 / abs(a - b),就可以求出多少天会相遇,然后就能求出A钟一共慢了多少秒,进而可以求出该时刻的时和分! 下面给...
1158 0