ZOJ Problem Set - 1201 Inversion (Python)
时间:2011-02-17 来源:天下之大
import sys
def readArraySize():
line = sys.stdin.readline()
a = line.split()
n = int(a[0])
return n
def main():
n = readArraySize()
while (n) != 0:
line = sys.stdin.readline()
a = line.split()
m = a.pop(0)
if m == 'P':
P2I(a, n)
else:
I2P(a, n)
n = readArraySize()
return 0
def P2I(b, n):
result = [0] * n
for i in range(n):
for j in range(i):
if b[j] > b[i]:
result[int(b[i]) - 1] = result[int(b[i]) - 1] + 1
print result
def I2P(b, n):
result = [n + 1] * n
for i in range(n):
j = 0
while result[j] < i + 1:
j = j + 1
for k in range(int(b[i])): #find a place for i+1
j = j + 1
while result[j] < i + 1:
j = j + 1
result[j] = i + 1
print result
if __name__ == '__main__':
main()
最近对AC有困扰啊。。。测试通过,无法AC,无法找出bug,请高手斧正!
相关阅读 更多 +