Codeforce 264 B Caisa and Pylons(模拟)
来源:互联网 发布:linux jsp一键安装包 编辑:程序博客网 时间:2024/05/10 20:47
题意 Caisa走台阶 有n个台阶 第i个台阶的高度为h[i] 从第i个台阶包括地面到下一个台阶得到的能量为h[i]-h[i+1] 能量不足以跳到下一个台阶就要补充能量 求Caisa跳完所有台阶最少要补充多少能量
水题 直接模拟
#include<cstdio>#include<cstring>using namespace std;const int N = 100005;int h[N];int main(){ int n, e, ans; scanf("%d",&n); for (int i = 1; i <= n; ++i) scanf ("%d", &h[i]); ans = 0; for (int i = e = 0; i < n; ++i) { if (h[i] + e < h[i + 1]) { int t = (h[i + 1] - e - h[i]); h[i] += t; ans += t; } e += (h[i] - h[i + 1]); } printf ("%d\n", ans); return 0;}
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time.
Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
53 4 3 2 4
4
34 4 4
4
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
- Codeforce 264 B Caisa and Pylons(模拟)
- B. Caisa and Pylons
- 【CODEFORCES】 B. Caisa and Pylons
- 463B. Caisa and Pylons
- Codeforces Round #264 (div2)B. Caisa and Pylons
- Codeforces Round #264 (Div. 2) 463B Caisa and Pylons
- Codeforces Round #264 (Div. 2) B. Caisa and Pylons
- Codeforces Round #264 (Div. 2)-B. Caisa and Pylons
- codeforces-#463B. Caisa and Pylons
- codeforces B#264. Caisa and Pylons
- Codeforces 463B Caisa and Pylons(水题)
- codeforces 463 B Caisa and Pylons
- Codeforces 463B Caisa and Pylons【二分】
- codeforces 463B Caisa and Pylons
- Caisa and Pylons
- Codeforce 264 A Caisa and Sugar(简单)
- CF 463E Caisa and Tree (模拟)
- 【模拟】Codeforce 302B
- 回文字符串
- java注解
- Windows 2008 Server搭建Radius服务器的方法
- 关于更换手机的安全问题
- oracle中 connect by prior 递归算法 -- 理解
- Codeforce 264 B Caisa and Pylons(模拟)
- 题目1389:变态跳台阶
- 《念奴娇·断虹霁雨》 黄庭坚
- LeetCode 42 Balanced Binary Tree
- Codeforces Round #264 (div2)B. Caisa and Pylons
- Java虚拟机学习 - 体系结构 内存模型
- Portal认证WEB服务器建立规范
- JavaScript 中数组的创建操作方法
- Ubuntu14.04安装chrome