Topcoder problem에서 코드를 실행하면 IndexError : 목록 색인이 범위를 벗어났습니다. 그러나 코드는 Python IDLE에서 완벽하게 작동했습니다. 누가 잘못했는지 말해 줄 수 있니? 당신의 data
때문에 탑 코더에서 제공하는 테스트 입력에 예기치 않은 EOF에 비어 있기 때문에IndexError : Topcoder 제출에 범위를 벗어난 색인을 나열하십시오.
Problem Info:
Definition Class:
CheeseSlicing Method: totalArea
Parameters: integer, integer, integer, integer
Returns: integer Method
signature: def totalArea(self, A, B, C, S):
Examples
0) 1 3 3 2
Returns: 0
One of the dimensions of this block is 1. Regardless of how we cut it, each piece will have one dimension equal to 1. As S=2, this means that producing a good slice is impossible. Hence, the maximum total surface area of good slices is 0.
import sys
total=0
data=sys.stdin.read().split()
x,y,z,s=int(data[0]),int(data[1]),int(data[2]),int(data[3])
if min(x,y,z)==s:
print x*y*z/s
elif min(x,y,z)<s:
print 0
elif max(x,y,z)>s:
lines=[x,y,z]
while max(lines)>=2*s:
area=1
maxline=max(lines)
lines.pop(lines.index(maxline))
for line in lines:
area=area*line
total+=area
lines.append(maxline-s)
area=1
minline=min(lines)
lines.pop(lines.index(minline))
for line in lines:
area=area*line
total+=area
print total
이 코드가 어떻게 유휴 상태에서 완벽하게 작동하는지 알 수 없습니다. split() 함수는 하나의 항목으로 목록을 반환합니다. –
이 문제에 대한 유효성 검사 테스트에 몇 가지 문제가있을 수 있습니다. –
예를 들어, 입력은 '5 5 5 2'이고 split() 함수는 [ '5', '5', '5', '2']를 반환합니다. –