赞
踩
- import java.util.Scanner;
-
- /**
- * className:test7_2
- * Package:PACKAGE_NAME
- *
- * @Author:swx
- * @Create2024/1/1119:57
- * @version:1.0
- */
- public class test7_2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- int res = 0;
- int[] arr = new int[n];
- for (int i = 0; i < n; i++) {
- arr[i] = scanner.nextInt();
- }
- for (int i=n-1; i>=0; i--) {
- /*当H>E时, E' = E-(H-E) = 2E-H
- 当H<E时, E' = E+(E-H) = 2E-H
- 所以,不管那个数答,最后的能量都是2E-H
- 那么 E = (E'+H)/2
- 最后一部假设能量正好为0
- * */
- int temp = res + arr[i]; //(E'+H)
- if (temp % 2 == 0) {
- res = temp / 2; // (E'+H)/2
- } else {
- res = temp / 2 + 1; // 向上取整
- }
- }
- System.out.println(res);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。