1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
int countAll(const vector int> & v)
{
size_t nEnd = v.size();
//寻找最大值的位置
size_t nMax = L2RfindMax(v, 0, nEnd);
std::cout << "M:" << nMax << std::endl;
//计算最大值左边能放多少水
size_t nSecRight = nMax;
size_t nSecRightEnd = 0;
int nTotal = 0;
while (nSecRight < nEnd - 1)
{
std::cout<<"R:"<<nSecRight<<std::endl;
nSecRightEnd = L2RfindMax(v, nSecRight + 1, nEnd);
nTotal += calculateOne(v, nSecRight, nSecRightEnd);
nSecRight = nSecRightEnd;
}
//计算最大值右边能放多少水
size_t nSecLift = nMax;
size_t nSecLiftEnd = 0;
while (nSecLift > 0)
{
std::cout << "L:" << nSecLift << std::endl;
nSecLiftEnd = R2LFindMax(v, 0, nSecLift - 1);
nTotal += calculateOne(v, nSecLiftEnd, nSecLift);
nSecLift = nSecLiftEnd;
}
return nTotal;
}
|