题目来自leetcode.com
11. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container and n is at least 2.
class Solution():
def __init__(self, _1 = 0, _2 = 0, area = 0):
self._1 = _1
self._2 = _2
self.area = 0
def update(self,_1,_2,area):
self._1 = _1
self._2 = _2
self.area = area
def _area(_1,_2,an):
_2 = _2 - _1
if an[_1] >= an[_2]:
return an[_2]*_2
else:
return an[_1]*_2
ans = Solution()
n = input("Input the number ")
n = int(n)
an = []
a = 0
while a<n:
b = input()
b = int(b)
an.append(b)
a += 1
a = 0
ma = 0
while a<n-1:
b = a+1
while b<n:
c = _area(a,b,an)
if ma < c:
ma = c
ans.update(a,b,c)
b += 1
a += 1
print("zui da zhi zuo biao :")
print('('+str(ans._1+1)+','+str(an[ans._1])+')'+'\n'+'('+str(ans._2+1)+','+str(an[ans._2])+')')
print("area :")
print(str(ans.area))