7-1
Panda and PP Milk
(20分)
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 nnn (≤104\le 10^4≤104) is given as the number of pandas. Then in the next line, nnn 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
本质是一个逻辑题 交错比较赋值 想复杂了
拆成两个阶段 都往左看 不争斗的情况 自己的体重大多 相等体重 相等
后一个体重更大 +100 要让体重更大察觉到不同
体重相等 相等
小于 200
样例中有更多意思 比如体重更大时即使前面>100察觉不同也不会影响公平(暗含)
题意:熊猫喝奶 * 思路:从左往右扫描一遍,设node[0].milk=200,对于i<j,若node[j].weight>node[i].weight,则node[j].milk=node[i].milk+100,若相等,则node[j].milk=node[i].milk * 若小于,则重新赋为200。这样就保证了所有熊猫都不会与左边的熊猫打架 * 而再从右往左扫描一遍,同理保证了所有熊猫不会与右边的熊猫打架,取两次序列中较大的值作为最终的奶量即可。 * @return
#include<bits/stdc++.h>
using namespace std;
//lo ji jc co
vector<int> ans1,ans2,ans;
int main(){
int n,_1;
scanf("%d",&n);
int book[n];
for(int i=0;i<n;i++){
scanf("%d",&book[i]);
}
ans1.push_back(200);
for(int i=1;i<n;i++){
if(book[i]>book[i-1]) ans1.push_back(ans1[i-1]+100);
else if(book[i]==book[i-1]) ans1.push_back(ans1[i-1]);
else ans1.push_back(200);//一开始头只是往左边看自己的多更不会争斗 分阶段
}
ans2.resize(n);
ans2[n-1]=200;
for(int i=n-2;i>=0;i--){
if(book[i]>book[i+1]) ans2[i]=ans2[i+1]+100;
else if(book[i]==ans2[i+1]) ans2[i]=ans2[i+1];
else ans2[i]=200;
}
int sum=0;
for(int i=0;i<n;i++){
sum+=max(ans1[i],ans2[i]);
}
printf("%d",sum);
return 0;
}
版权声明:本文为qq_40563761原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.youkuaiyun.com/qq_40563761/article/details/108716400