蓄水池蓄水问题

来源:互联网 发布:电脑流量监测软件 编辑:程序博客网 时间:2024/05/04 03:36
// Water pool.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <windows.h>#include <iostream>using namespace std;int Volume(int * height, int n){    int result = 0;    int p_now = 1, p_prev = 0, p_prevprev = -1;    int zeropool = 1;    int p_highestleft = 0;    int lengthbrick = 0;    int h_highnext = 0;    if (height[p_now] < height[p_prev])        zeropool = 0;    for (size_t i = 2; i < n; i++)    {        p_now = i;        p_prev = i - 1;        p_prevprev = i - 2;        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 + 1; 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 + 1; j < p_prev; j++)                    {                        result += height[p_highestleft] - height[j];                    }                    p_highestleft = p_prev;                    lengthbrick = 0;                    h_highnext = height[p_now];                }            }            else //(zeropool)            {                zeropool = 0;                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 - 1;    p_prevprev = n - 2;    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 + 1; 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 + 1; j < p_prev; j++)                {                    result += height[p_highestleft] - height[j];                }            }        }    }    cout << result;    return result;}int main(void){    int A[] = { 3, 2, 1, 2, 1, 2, 1, 2, 3 };//10    int n = 9;    //    //int A[] = { 3,2,1,2,1,2,3 };//7    //int n = 7;    Volume(A, n);    return 0;}
0 0
原创粉丝点击