2020PAT甲级秋季7-1 Panda and PP Milk

2023-12-09 11:48
文章标签 甲级 秋季 panda pp milk 2020pat

本文主要是介绍2020PAT甲级秋季7-1 Panda and PP Milk,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

7-1

Panda and PP Milk
在这里插入图片描述
PP milk (盆盆奶)is Pandas’ favorite. They would line up to enjoy it as show in the picture. On the other hand, they could drink in peace only if they believe that the amount of PP milk is fairly distributed, that is, fatter panda can have more milk, and the ones with equal weight may have the same amount. Since they are lined up, each panda can only compare with its neighbor(s), and if it thinks this is unfair, the panda would fight with its neighbor.

Given that the minimum amount of milk a panda must drink is 200 ml. It is only when another bowl of milk is at least 100 ml more than its own that a panda can sense the difference.

Now given the weights of a line of pandas, your job is to help the breeder(饲养员)to decide the minimum total amount of milk that he/she must prepare, provided that the pandas are lined up in the given order.

Input Specification:

Each input file contains one test case. For each case, first a positive integer n (≤10​4​​ ) is given as the number of pandas. Then in the next line, n positive integers are given as the weights (in kg) of the pandas, each no more than 200. the numbers are separated by spaces.

Output Specification:

For each test case, print in a line the minimum total amount of milk that the breeder must prepare, to make sure that all the pandas can drink in peace.

Sample Input:

10
180 160 100 150 145 142 138 138 138 140

Sample Output:

3000

Hint:

The distribution of milk is the following:

400 300 200 500 400 300 200 200 200 300

#include<bits/stdc++.h>
using namespace std;
int N;
vector<int> w, lefts;
int main() {scanf("%d", &N);w.resize(N);lefts.resize(N);for (int i = 0; i < N; i++) {lefts[i]  = 200;scanf("%d", &w[i]);}for (int i = N - 2; i >= 0; i--) {if (w[i] > w[i + 1] && lefts[i] <= lefts[i + 1]) {lefts[i] = lefts[i + 1] + 100;} else if (w[i] < w[i + 1] && lefts[i + 1] <= lefts[i]) {lefts[i + 1] = lefts[i] + 100;} else if (w[i] == w[i + 1]) {int maxs = max(lefts[i], lefts[i + 1]);lefts[i] = maxs;lefts[i + 1] = maxs;}}for (int i = 1; i <= N - 1; i++) {if (w[i] > w[i - 1] && lefts[i] <= lefts[i - 1]) {lefts[i] = lefts[i - 1] + 100;} else if (w[i] < w[i - 1] && lefts[i] >= lefts[i - 1]) {lefts[i - 1] = lefts[i] + 100;} else if (w[i] == w[i - 1]) {if (lefts[i] != lefts[i - 1]) {int maxs = max(lefts[i], lefts[i - 1]);lefts[i] = maxs;lefts[i - 1] = maxs;}}}int sum = 0;for (int i = 0; i < N; i++) {sum += lefts[i] ;}cout << sum;return 0;
}

这篇关于2020PAT甲级秋季7-1 Panda and PP Milk的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/473665

相关文章

usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)

到了这题学会了结构体排序 于是回去修改了 1.2 milking cows 的算法~ 结构体排序核心: 1.结构体定义 struct Milk{int price;int milks;}milk[5000]; 2.自定义的比较函数,若返回值为正,qsort 函数判定a>b ;为负,a<b;为0,a==b; int milkcmp(const void *va,c

LeetCode560. 和为 K 的子数组(2024秋季每日一题 12)

给你一个整数数组 n u m s nums nums 和一个整数 k k k ,请你统计并返回 该数组中和为 k k k 的子数组的个数 。 子数组是数组中元素的连续非空序列。 示例 1: 输入:nums = [1,1,1], k = 2 输出:2 示例 2: 输入:nums = [1,2,3], k = 3 输出:2 提示: 1 < = n u m s . l

PAT甲级-1044 Shopping in Mars

题目   题目大意 一串项链上有n个钻石,输入给出每个钻石的价格。用m元买一个连续的项链子串(子串长度可为1),如果不能恰好花掉m元,就要找到最小的大于m的子串,如果有重复就输出多个,按递增顺序输出子串的前端和后端索引。 原来的思路 取连续的子串使和恰等于m,没有恰等于就找最小的大于。可以将子串依次累加,使得每个位置都是起始位置到该位置的序列和,整个数组显递增顺序,就可以用右边减左边

LeetCode438. 找到字符串中所有字母异位词(2024秋季每日一题 11)

给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引。不考虑答案输出的顺序。 异位词 指由相同字母重排列形成的字符串(包括相同的字符串)。 示例 1: 输入: s = “cbaebabacd”, p = “abc” 输出: [0,6] 解释: 起始索引等于 0 的子串是 “cba”, 它是 “abc” 的异位词。 起始索引等于 6 的子串是

[SWPUCTF 2023 秋季新生赛]Pingpingping

这种是ctf中比较简单的一类题,主要解法基本上也就那些形式。 这道题我给它提出来主要是涉及了一下比较零散的知识点,觉得想要跟大家分享一下。 <?phphighlight_file(__FILE__);error_reporting(0);$_ping = $_GET['Ping_ip.exe'];if(isset($_ping)){system("ping -c 3 ".$_ping)

PP强酸强碱氮气柜和普通氮气柜的区别及共同点

PP强酸强碱氮气柜通常采用聚丙烯(PP)材料制成,聚丙烯是一种耐腐蚀性强的塑料材质,能有效抵抗强酸、强碱、盐溶液等腐蚀性物质的侵蚀,不易老化,使用寿命长。因其优秀的化学稳定性和耐腐蚀性,特别适合存储那些需要避免与外界湿气或氧气接触,并且本身可能产生或已处于强酸强碱环境中的物品。 PP强酸强碱氮气柜,柜体采用瓷白色PP板材,一体成型,经过无缝焊接处理,坚固耐用。层板同样采用PP板材,整块加强焊接,主

【LLM】文生视频相关开源数据集(VidGen、Panda、Cogvideox等)

note 总结了VidGen数据集、Panda-70m数据集、Openvid数据集、OpenVid-1M数据集、Cogvideox训练数据准备过程、ShareGPT4Video数据集等在一篇综述中还总结了评估指标包括:峰值信噪比(PSNR)、结构相似性指数(SSIM)、Inception 分数(IS)、Fréchet Inception 距离(FID)、CLIP 分数、视频 Inception

万万没想到!秋季里的这些水果,对帕金森治疗大有裨益!——蔡英丽医生

随着秋风轻拂,大地披上了一袭金黄色的外衣,这不仅是收获的季节,更是自然对人类健康的又一次慷慨馈赠。对于帕金森病患者而言,这个秋季尤为特别,因为大自然悄然间准备了五种神奇的秋季水果,它们不仅是味蕾的享受,更是治疗路上的得力助手。 葡萄:紫色的健康密码 首当其冲的是葡萄,这串串晶莹剔透的果实中蕴藏着丰富的微量元素,是营养宝库中的佼佼者。而葡萄籽更是不可多得的宝贝,它们富含抗氧化剂与多种有益物质

国科大 矩阵论2023秋季 叶世伟老师 考试试卷

叶老师的考试很难,图源一位胆大的勇者~ 希望能帮助大家!

1050 String Subtraction——PAT甲级

Given two strings S1​ and S2​, S=S1​−S2​ is defined to be the remaining string after taking all the characters in S2​ from S1​. Your task is simply to calculate S1​−S2​ for any given strings. However,