蓄水池蓄水问题
来源:互联网 发布:电脑流量监测软件 编辑:程序博客网 时间: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
- 蓄水池蓄水问题
- 台阶蓄水问题
- 蓄水池问题
- 蓄水池问题
- 蓄水池问题
- 蓄水池问题
- 蓄水池问题
- 水 water 积水问题 蓄水问题
- Google面试题——蓄水问题
- 直方图蓄水问题 Trapping Rain Water
- 水池蓄水问题(Trapping Rain Water)
- 蓄水池抽样问题
- 蓄水池抽样问题
- 蓄水池抽样问题
- 蓄水池抽样问题
- 蓄水池问题分析证明
- 蓄水池抽样问题
- reservoid sample 蓄水池问题
- python copy & deepcopy 区别
- cent 网络设置
- 在MyEclipse10中修改servlet模板
- 离线安装Cloudera Manager 5和CDH5(最新版5.1.3) 完全教程
- spring容器启动之我见(一)
- 蓄水池蓄水问题
- python中类属性和实例属性的区别
- 字符串操作函数
- 第四周项目 2 对象作为数据成员
- 多线程GCD的使用及介绍
- Android --使用SharedPreferences保存和获取数据
- LeetCode:Two Sum
- Weblogic12c(12.1.3)安装和eclipse下配置weblogic并发布项目
- Andriod getWindow().getDecorView()理解