自学内容网 自学内容网

1172 Panda and PP Milk——PAT甲级

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

 solution:
 

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
int main()
{
int n;cin>>n;
vector<int>a(n+2);
int sum=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
int l=0,r=0;
for(int j=i-1;j>=1;j--)
{
if(a[j]<a[j+1])l++;
else if(a[j]>a[j+1])break;
}
for(int j=i+1;j<=n;j++)
{
if(a[j-1]>a[j])r++;
else if(a[j-1]<a[j])break;
}
sum+=200+100*max(l,r);
}
cout<<sum;
}


原文地址:https://blog.csdn.net/flyidj/article/details/143572928

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!