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 (≤104) 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
题目意思:熊猫至少喝200ml牛奶,不同重量有差异,差异至少是100ml,相同重量,喝的牛奶相同。
思路:先给每个熊猫都分200ml牛奶,再从头到尾遍历一遍和邻居比较重量,同时比较牛奶量,对于不满足重的喝的多这个条件的每次+100,直到进行到全部满足。注意:对于相同重量由于两边的邻居不同,所以再相同重量的这个地方我们还需要进行比较,以保证他们满足相同重量喝的牛奶量相同。
代码如下:
#include<iostream>
using namespace std;
const int N=10005;
int a[N]={0},s[N]={0},sum=0;
int main(){
int n,MIN=N;
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++){
s[i]=200;
}
int flag=1,tmp=1;
while(flag==1){
tmp=1;
for(int i=0;i<n;i++){
if((a[i]>a[i+1]&&s[i]<=s[i+1])){//左边对右边的影响
s[i]+=100;
tmp=0;
}else if((a[i]>a[i-1]&&s[i]<=s[i-1])){// 右对左的影响
s[i]+=100;
tmp=0;
}else if(a[i]==a[i+1]&&s[i]<s[i+1]){
s[i]+=100;
tmp=0;
}else if(a[i]==a[i+1]&&s[i]>s[i+1]){
s[i+1]+=100;
tmp=0;
}
}
if(tmp==1)flag=0;
}
for(int i=0;i<n;i++){
//cout<<s[i]<<" ";
sum+=s[i];
}
cout<<sum;
return 0;
}