// Water pool.cpp : 定義控制台應用程式的入口點。
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
int Volume(int * height, int n)
{
int result = ;
int p_now = , p_prev = , p_prevprev = -;
int zeropool = ;
int p_highestleft = ;
int lengthbrick = ;
int h_highnext = ;
if (height[p_now] < height[p_prev])
zeropool = ;
for (size_t i = ; i < n; i++)
{
p_now = i;
p_prev = i - ;
p_prevprev = i - ;
if ((height[p_now] < height[p_prev]) && (height[p_prevprev] < height[p_prev]))
{
cout << "xushui" << endl;
if (!zeropool)
{
if (height[p_highestleft] > height[p_prev])
{
result += lengthbrick*(height[p_prev] - h_highnext);
for (size_t j = p_highestleft + lengthbrick + ; j < p_prev; j++)
{
result += height[p_prev] - height[j];
}
lengthbrick = p_prev - p_highestleft;
h_highnext = height[p_prev];
}
else //(height[p_highestleft] <= height[p_prev])
{
result += lengthbrick*(height[p_highestleft] - h_highnext);
for (size_t j = p_highestleft + lengthbrick + ; j < p_prev; j++)
{
result += height[p_highestleft] - height[j];
}
p_highestleft = p_prev;
lengthbrick = ;
h_highnext = height[p_now];
}
}
else //(zeropool)
{
zeropool = ;
p_highestleft = p_prev;
h_highnext = height[p_now];
}
}
else //if ((height[p_now] < height[p_prev]) && (height[p_prevprev] < height[p_prev]))
{
}
//cout << i << ":"<<result << endl;
}
p_prev = n - ;
p_prevprev = n - ;
if ((height[p_prevprev] < height[p_prev]))
{
if (!zeropool)
{
if (height[p_highestleft] > height[p_prev])
{
result += lengthbrick*(height[p_prev] - h_highnext);
for (size_t j = p_highestleft + lengthbrick + ; j < p_prev; j++)
{
result += height[p_prev] - height[j];
}
}
else //(height[p_highestleft] <= height[p_prev])
{
result += lengthbrick*(height[p_highestleft] - h_highnext);
for (size_t j = p_highestleft + lengthbrick + ; j < p_prev; j++)
{
result += height[p_highestleft] - height[j];
}
}
}
}
cout << result;
return result;
}
int main(void)
{
int A[] = { , , , , , , , , };//10
int n = ;
//
//int A[] = { 3,2,1,2,1,2,3 };//7
//int n = 7;
Volume(A, n);
return ;
}