Basic Solution
This commit is contained in:
parent
3b0fd8392b
commit
66964953a8
@ -1 +1,186 @@
|
|||||||
1
|
LoadCarrots 12
|
||||||
|
LoadGift Nelly9621
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Stefan1846
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Stepan6060
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Clement2007
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Matas6172
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Petar5664
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Matas2180
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Przemek1941
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccRight 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 1
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Tatiyana4230
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccUp 1
|
||||||
|
Float 1
|
||||||
|
AccDown 1
|
||||||
|
Float 1
|
||||||
|
AccLeft 2
|
||||||
|
Float 1
|
||||||
|
AccRight 2
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Michal5548
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Przemek4289
|
||||||
|
AccRight 3
|
||||||
|
Float 1
|
||||||
|
AccLeft 3
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccUp 2
|
||||||
|
Float 1
|
||||||
|
AccDown 2
|
||||||
|
Float 1
|
||||||
|
AccLeft 3
|
||||||
|
Float 1
|
||||||
|
AccRight 3
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Max1879
|
||||||
|
AccUp 4
|
||||||
|
Float 1
|
||||||
|
AccDown 4
|
||||||
|
Float 1
|
||||||
|
AccDown 4
|
||||||
|
Float 1
|
||||||
|
AccUp 4
|
||||||
|
Float 1
|
||||||
|
LoadCarrots 12
|
||||||
|
LoadGift Przemek4984
|
||||||
|
@ -2,6 +2,7 @@ from math import sqrt
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def is_number(s):
|
def is_number(s):
|
||||||
try:
|
try:
|
||||||
float(s)
|
float(s)
|
||||||
@ -12,10 +13,11 @@ def is_number(s):
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
unicodedata.numeric(s)
|
unicodedata.numeric(s)
|
||||||
return True
|
return True
|
||||||
except (TypeError,ValueError):
|
except (TypeError, ValueError):
|
||||||
pass
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def convertToFloat(DataSet):
|
def convertToFloat(DataSet):
|
||||||
for i in range(len(DataSet)):
|
for i in range(len(DataSet)):
|
||||||
for j in range(len(DataSet[i])):
|
for j in range(len(DataSet[i])):
|
||||||
@ -23,11 +25,13 @@ def convertToFloat(DataSet):
|
|||||||
DataSet[i][j] = float(DataSet[i][j])
|
DataSet[i][j] = float(DataSet[i][j])
|
||||||
return DataSet
|
return DataSet
|
||||||
|
|
||||||
|
|
||||||
def caculateDistance(a: list, b: tuple):
|
def caculateDistance(a: list, b: tuple):
|
||||||
d = sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
|
d = sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def readLine(m = 0, n = 2, offset = 1):
|
|
||||||
|
def readLine(m=0, n=2, offset=1):
|
||||||
global DataSet
|
global DataSet
|
||||||
lenth = int(DataSet[m][n])
|
lenth = int(DataSet[m][n])
|
||||||
line = []
|
line = []
|
||||||
@ -35,11 +39,13 @@ def readLine(m = 0, n = 2, offset = 1):
|
|||||||
line.append(DataSet[i + offset])
|
line.append(DataSet[i + offset])
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
class Person:
|
class Person:
|
||||||
priority:float
|
priority: float
|
||||||
|
|
||||||
def __init__(self, infomationLine):
|
def __init__(self, infomationLine):
|
||||||
self.name, self.score, self.weightOfGift, self.x_position, self.y_position = infomationLine
|
self.name, self.score, self.weightOfGift, self.x_position, self.y_position = infomationLine
|
||||||
|
|
||||||
def getPosition(self):
|
def getPosition(self):
|
||||||
return (self.x_position, self.y_position)
|
return (self.x_position, self.y_position)
|
||||||
|
|
||||||
@ -48,14 +54,15 @@ class Person:
|
|||||||
Score += self.score
|
Score += self.score
|
||||||
|
|
||||||
def caculatePriority(self):
|
def caculatePriority(self):
|
||||||
return self.score / (self.weightOfGift * caculateDistance([0,0], (self.x_position, self.y_position)))
|
return self.score / (self.weightOfGift * caculateDistance([0, 0], (self.x_position, self.y_position)))
|
||||||
|
|
||||||
|
|
||||||
class People:
|
class People:
|
||||||
info = []
|
info = []
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global DataSet
|
global DataSet
|
||||||
line = readLine(m = 0, n = 3, offset = 1 + int(DataSet[0][2]))
|
line = readLine(m=0, n=3, offset=1 + int(DataSet[0][2]))
|
||||||
for i in line:
|
for i in line:
|
||||||
self.info.append(Person(i))
|
self.info.append(Person(i))
|
||||||
|
|
||||||
@ -71,10 +78,11 @@ class People:
|
|||||||
|
|
||||||
class Santa:
|
class Santa:
|
||||||
tableauDeDistribution = []
|
tableauDeDistribution = []
|
||||||
position = [0.0,0.0]
|
position = [0.0, 0.0]
|
||||||
speed = [0.0,0.0]
|
speed = [0.0, 0.0]
|
||||||
weightOfCarrots:int = 0
|
weightOfCarrots: int = 0
|
||||||
weightOfGift:int = 0
|
weightOfGift: int = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global DataSet
|
global DataSet
|
||||||
self.timeLimit = int(DataSet[0][0])
|
self.timeLimit = int(DataSet[0][0])
|
||||||
@ -94,9 +102,9 @@ class Santa:
|
|||||||
if w < self.speedLimitTable[i][0]:
|
if w < self.speedLimitTable[i][0]:
|
||||||
return self.speedLimitTable[i][1]
|
return self.speedLimitTable[i][1]
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# DONE 此速度限制speedLimit为限制表不是当前限制,我们下一步要定义nowspeedLimit
|
# DONE 此速度限制speedLimit为限制表不是当前限制,我们下一步要定义nowspeedLimit
|
||||||
|
|
||||||
def isAllowedBySpeedLimit(self, s):
|
def isAllowedBySpeedLimit(self, s):
|
||||||
return s <= self.nowSpeedLimit()
|
return s <= self.nowSpeedLimit()
|
||||||
|
|
||||||
@ -105,301 +113,301 @@ class Santa:
|
|||||||
self.weightOfCarrots -= 1
|
self.weightOfCarrots -= 1
|
||||||
|
|
||||||
def AccUp(self, s):
|
def AccUp(self, s):
|
||||||
if self.timeLimit>0:
|
if self.timeLimit > 0:
|
||||||
assert self.isAllowedBySpeedLimit(s)
|
assert self.isAllowedBySpeedLimit(s)
|
||||||
self.speed[1] += s
|
self.speed[1] += s
|
||||||
self.consumeCarrot()
|
self.consumeCarrot()
|
||||||
print("AccUp",int(s), file=output)
|
print("AccUp", int(s), file=output)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def AccDown(self, s):
|
def AccDown(self, s):
|
||||||
if self.timeLimit>0:
|
if self.timeLimit > 0:
|
||||||
assert self.isAllowedBySpeedLimit(s)
|
assert self.isAllowedBySpeedLimit(s)
|
||||||
self.speed[1] -= s
|
self.speed[1] -= s
|
||||||
self.consumeCarrot()
|
self.consumeCarrot()
|
||||||
print("AccDown",int(s), file=output)
|
print("AccDown", int(s), file=output)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def AccRight(self, s):
|
def AccRight(self, s):
|
||||||
if self.timeLimit>0:
|
if self.timeLimit > 0:
|
||||||
assert self.isAllowedBySpeedLimit(s)
|
assert self.isAllowedBySpeedLimit(s)
|
||||||
self.speed[0] += s
|
self.speed[0] += s
|
||||||
self.consumeCarrot()
|
self.consumeCarrot()
|
||||||
print("AccRight",int(s), file=output)
|
print("AccRight", int(s), file=output)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def AccLeft(self, s):
|
def AccLeft(self, s):
|
||||||
if self.timeLimit>0:
|
if self.timeLimit > 0:
|
||||||
assert self.isAllowedBySpeedLimit(s)
|
assert self.isAllowedBySpeedLimit(s)
|
||||||
self.speed[0] -= s
|
self.speed[0] -= s
|
||||||
self.consumeCarrot()
|
self.consumeCarrot()
|
||||||
print("AccLeft",int(s), file=output)
|
print("AccLeft", int(s), file=output)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def LoadCarrots(self, w):
|
def LoadCarrots(self, w):
|
||||||
self.weightOfCarrots += w
|
self.weightOfCarrots += w
|
||||||
|
|
||||||
def LoadGift(self, w):
|
def LoadGift(self, w):
|
||||||
self.weightOfGift += w
|
self.weightOfGift += w
|
||||||
|
|
||||||
def DiliveryGift(self,p: Person):
|
def DiliveryGift(self, p: Person):
|
||||||
if self.timeLimit >=0 and caculateDistance(self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit:
|
if self.timeLimit >= 0 and caculateDistance(self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit:
|
||||||
assert caculateDistance(self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit
|
assert caculateDistance(
|
||||||
self.weightOfGift -= p.weightOfGift
|
self.getPosition(), p.getPosition()) <= self.deliveryDistanceLimit
|
||||||
assert self.weightOfGift >= 0
|
self.weightOfGift -= p.weightOfGift
|
||||||
p.getScore()
|
assert self.weightOfGift >= 0
|
||||||
print("DeliverGift",p.name, file=output)
|
p.getScore()
|
||||||
|
print("DeliverGift", p.name, file=output)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def Float(self, t:int = 1):
|
def Float(self, t: int = 1):
|
||||||
if (self.timeLimit - t) >=0:
|
if (self.timeLimit - t) >= 0:
|
||||||
self.position[0] += self.speed[0] * t
|
self.position[0] += self.speed[0] * t
|
||||||
self.position[1] += self.speed[1] * t
|
self.position[1] += self.speed[1] * t
|
||||||
self.timeLimit -= t
|
self.timeLimit -= t
|
||||||
print("Float",int(t), file=output)
|
print("Float", int(t), file=output)
|
||||||
else:
|
else:
|
||||||
self.timeLimit -= self.timeLimit
|
self.timeLimit -= self.timeLimit
|
||||||
|
|
||||||
def getSituation(self):
|
def getSituation(self):
|
||||||
print("Now position is:",self.position)
|
print("Now position is:", self.position)
|
||||||
print("Now speed is:",self.speed)
|
print("Now speed is:", self.speed)
|
||||||
print("Now timeLimit is:",self.timeLimit)
|
print("Now timeLimit is:", self.timeLimit)
|
||||||
print("Now weightOfGift is:",self.weightOfGift)
|
print("Now weightOfGift is:", self.weightOfGift)
|
||||||
print("Now weightOfCarrots is:",self.weightOfCarrots)
|
print("Now weightOfCarrots is:", self.weightOfCarrots)
|
||||||
|
|
||||||
|
|
||||||
def generateTableauDeDistribution(self, pp: People):
|
def generateTableauDeDistribution(self, pp: People):
|
||||||
self.tableauDeDistribution = sorted(pp.info, key=lambda x: x.caculatePriority(), reverse=True)
|
self.tableauDeDistribution = sorted(
|
||||||
|
pp.info, key=lambda x: x.caculatePriority(), reverse=True)
|
||||||
return self.tableauDeDistribution
|
return self.tableauDeDistribution
|
||||||
|
|
||||||
|
def kidoneWay(self, x: int, p: Person):
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
def kidoneWay(self,x:int,p:Person):
|
if isinstance(x/v, int) and x > 0:
|
||||||
v = self.nowSpeedLimit()
|
t = x/v
|
||||||
if isinstance(x/v,int) and x > 0 :
|
self.AccUp(v)
|
||||||
t = x/v
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
t = x/v
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
|
|
||||||
elif isinstance(x/v,int) and x < 0 :
|
|
||||||
t = abs(x)/v
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
t = abs(x)/v
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif x < v and x > 0 :
|
|
||||||
v = x
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
v = x
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float()
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif abs(x) < v and x < 0 :
|
|
||||||
v = abs(x)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
v = abs(x)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif x > v and x > 0 :
|
|
||||||
t = x//v
|
|
||||||
v1 = v - (x - t*v)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccDown(v1)
|
|
||||||
self.Float()
|
|
||||||
self.AccDown(v - v1)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
t = x//v
|
|
||||||
v1 = v - (x - t*v)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccUp(v1)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccUp(v - v1)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif abs(x) > v and x < 0 :
|
|
||||||
t = abs(x)//v
|
|
||||||
v1 = v - (abs(x) - t*v)
|
|
||||||
self.AccDown(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccUp(v1)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccUp(v - v1)
|
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
|
|
||||||
t = abs(x)//v
|
|
||||||
v1 = v - (abs(x) - t*v)
|
|
||||||
self.AccUp(v)
|
|
||||||
self.Float(t)
|
|
||||||
self.AccDown(v1)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccDown(v - v1)
|
|
||||||
self.Float(1)
|
|
||||||
else:
|
|
||||||
self.DiliveryGift(p)
|
|
||||||
|
|
||||||
def oneWay(self, p:Person):
|
|
||||||
if self.timeLimit >0:
|
|
||||||
self.LoadCarrots(12)
|
|
||||||
print("LoadCarrots 12", file=output)
|
|
||||||
self.LoadGift(p.weightOfGift)
|
|
||||||
print("LoadGift",p.name, file=output)
|
|
||||||
v = self.nowSpeedLimit()
|
|
||||||
if isinstance(p.x_position/v,int) and p.x_position > 0 :
|
|
||||||
t = p.x_position/v
|
|
||||||
self.AccRight(v)
|
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccLeft(v)
|
self.AccDown(v)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
self.DiliveryGift(p)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
t = p.x_position/v
|
t = x/v
|
||||||
self.AccLeft(v)
|
self.AccDown(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccRight(v)
|
self.AccUp(v)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
|
elif isinstance(x/v, int) and x < 0:
|
||||||
elif isinstance(p.x_position/v,int) and p.x_position < 0:
|
t = abs(x)/v
|
||||||
t = abs(p.x_position)/v
|
self.AccDown(v)
|
||||||
self.AccLeft(v)
|
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccRight(v)
|
self.AccUp(v)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
|
||||||
|
|
||||||
t = abs(p.x_position)/v
|
self.DiliveryGift(p)
|
||||||
self.AccRight(v)
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
|
t = abs(x)/v
|
||||||
|
self.AccUp(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccLeft(v)
|
self.AccDown(v)
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif p.x_position < v and p.x_position > 0 :
|
|
||||||
v = p.x_position
|
|
||||||
self.AccRight(v)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccLeft(v)
|
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
elif x < v and x > 0:
|
||||||
|
v = x
|
||||||
v = p.x_position
|
self.AccUp(v)
|
||||||
self.AccLeft(v)
|
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
self.AccRight(v)
|
self.AccDown(v)
|
||||||
self.Float(1)
|
|
||||||
|
|
||||||
elif abs(p.x_position) < v and p.x_position < 0 :
|
|
||||||
v = abs(p.x_position)
|
|
||||||
self.AccLeft(v)
|
|
||||||
self.Float(1)
|
|
||||||
self.AccRight(v)
|
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
self.DiliveryGift(p)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
v = abs(p.x_position)
|
v = x
|
||||||
self.AccRight(v)
|
self.AccDown(v)
|
||||||
self.Float(1)
|
self.Float()
|
||||||
self.AccLeft(v)
|
self.AccUp(v)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
elif p.x_position > v and p.x_position > 0 :
|
elif abs(x) < v and x < 0:
|
||||||
t = p.x_position//v
|
v = abs(x)
|
||||||
v1 = v - (p.x_position - t*v)
|
self.AccDown(v)
|
||||||
self.AccRight(v)
|
self.Float(1)
|
||||||
|
self.AccUp(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.DiliveryGift(p)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
|
v = abs(x)
|
||||||
|
self.AccUp(v)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccDown(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif x > v and x > 0:
|
||||||
|
t = x//v
|
||||||
|
v1 = v - (x - t*v)
|
||||||
|
self.AccUp(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccLeft(v1)
|
self.AccDown(v1)
|
||||||
self.Float(1)
|
self.Float()
|
||||||
self.AccLeft(v - v1)
|
self.AccDown(v - v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
self.DiliveryGift(p)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
t = p.x_position//v
|
t = x//v
|
||||||
v1 = v - (p.x_position - t*v)
|
v1 = v - (x - t*v)
|
||||||
self.AccLeft(v)
|
self.AccDown(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccRight(v1)
|
self.AccUp(v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
self.AccRight(v - v1)
|
self.AccUp(v - v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
elif abs(p.x_position) > v and p.x_position < 0 :
|
elif abs(x) > v and x < 0:
|
||||||
t = abs(p.x_position)//v
|
t = abs(x)//v
|
||||||
v1 = v - (abs(p.x_position) - t*v)
|
v1 = v - (abs(x) - t*v)
|
||||||
self.AccLeft(v)
|
self.AccDown(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccRight(v1)
|
self.AccUp(v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
self.AccRight(v - v1)
|
self.AccUp(v - v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
|
|
||||||
self.kidoneWay(p.y_position,p)
|
self.DiliveryGift(p)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
|
||||||
t = abs(p.x_position)//v
|
t = abs(x)//v
|
||||||
v1 = v - (abs(p.x_position) - t*v)
|
v1 = v - (abs(x) - t*v)
|
||||||
self.AccRight(v)
|
self.AccUp(v)
|
||||||
self.Float(t)
|
self.Float(t)
|
||||||
self.AccLeft(v1)
|
self.AccDown(v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
self.AccLeft(v - v1)
|
self.AccDown(v - v1)
|
||||||
self.Float(1)
|
self.Float(1)
|
||||||
elif p.x_position == 0 :
|
else:
|
||||||
self.kidoneWay(p.y_position,p)
|
self.DiliveryGift(p)
|
||||||
|
|
||||||
|
def oneWay(self, p: Person):
|
||||||
|
if self.timeLimit > 0:
|
||||||
|
self.LoadCarrots(12)
|
||||||
|
print("LoadCarrots 12", file=output)
|
||||||
|
self.LoadGift(p.weightOfGift)
|
||||||
|
print("LoadGift", p.name, file=output)
|
||||||
|
v = self.nowSpeedLimit()
|
||||||
|
if isinstance(p.x_position/v, int) and p.x_position > 0:
|
||||||
|
t = p.x_position/v
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
t = p.x_position/v
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif isinstance(p.x_position/v, int) and p.x_position < 0:
|
||||||
|
t = abs(p.x_position)/v
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
t = abs(p.x_position)/v
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif p.x_position < v and p.x_position > 0:
|
||||||
|
v = p.x_position
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
v = p.x_position
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif abs(p.x_position) < v and p.x_position < 0:
|
||||||
|
v = abs(p.x_position)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
v = abs(p.x_position)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif p.x_position > v and p.x_position > 0:
|
||||||
|
t = p.x_position//v
|
||||||
|
v1 = v - (p.x_position - t*v)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccLeft(v1)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccLeft(v - v1)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
t = p.x_position//v
|
||||||
|
v1 = v - (p.x_position - t*v)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccRight(v1)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccRight(v - v1)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
elif abs(p.x_position) > v and p.x_position < 0:
|
||||||
|
t = abs(p.x_position)//v
|
||||||
|
v1 = v - (abs(p.x_position) - t*v)
|
||||||
|
self.AccLeft(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccRight(v1)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccRight(v - v1)
|
||||||
|
self.Float(1)
|
||||||
|
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
t = abs(p.x_position)//v
|
||||||
|
v1 = v - (abs(p.x_position) - t*v)
|
||||||
|
self.AccRight(v)
|
||||||
|
self.Float(t)
|
||||||
|
self.AccLeft(v1)
|
||||||
|
self.Float(1)
|
||||||
|
self.AccLeft(v - v1)
|
||||||
|
self.Float(1)
|
||||||
|
elif p.x_position == 0:
|
||||||
|
self.kidoneWay(p.y_position, p)
|
||||||
|
|
||||||
|
|
||||||
def line_prepender(f, line):
|
def line_prepender(f, line):
|
||||||
@ -413,29 +421,35 @@ Output_File_Directory = 'Output/'
|
|||||||
files = os.listdir(File_Directory)
|
files = os.listdir(File_Directory)
|
||||||
out_files = os.listdir(Output_File_Directory)
|
out_files = os.listdir(Output_File_Directory)
|
||||||
|
|
||||||
|
print('------------------Score--------------------------------')
|
||||||
for File_Name in files:
|
for File_Name in files:
|
||||||
|
|
||||||
File_Path = File_Directory+File_Name
|
File_Path = File_Directory+File_Name
|
||||||
Output_File_Path = Output_File_Directory+File_Name.replace("in", "out")
|
Output_File_Path = Output_File_Directory+File_Name.replace("in", "out")
|
||||||
DataSet = [line.strip().split() for line in open(File_Path, "r")]
|
DataSet = [line.strip().split() for line in open(File_Path, "r")]
|
||||||
DataSet = convertToFloat(DataSet)
|
DataSet = convertToFloat(DataSet)
|
||||||
|
|
||||||
Score:int = 0
|
Score: int = 0
|
||||||
s = Santa()
|
s = Santa()
|
||||||
pp = People()
|
pp = People()
|
||||||
s.generateTableauDeDistribution(pp)
|
s.generateTableauDeDistribution(pp)
|
||||||
|
|
||||||
|
output = open(Output_File_Path, "w")
|
||||||
|
|
||||||
output = open(Output_File_Path, "w+")
|
try:
|
||||||
|
|
||||||
try:
|
|
||||||
for i in s.generateTableauDeDistribution(pp):
|
for i in s.generateTableauDeDistribution(pp):
|
||||||
s.oneWay(i)
|
s.oneWay(i)
|
||||||
except:
|
except:
|
||||||
print("Error in this dataset", file=output)
|
# print("Error in this dataset", file=output)
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
print(File_Name, Score)
|
||||||
|
|
||||||
|
|
||||||
|
print('-------------------how many line in output file---------------')
|
||||||
|
|
||||||
|
|
||||||
def line_prepender(filename, line):
|
def line_prepender(filename, line):
|
||||||
with open(filename, 'r+') as f:
|
with open(filename, 'r+') as f:
|
||||||
@ -443,6 +457,7 @@ def line_prepender(filename, line):
|
|||||||
f.seek(0, 0)
|
f.seek(0, 0)
|
||||||
f.write(line.rstrip('\r\n') + '\n' + content)
|
f.write(line.rstrip('\r\n') + '\n' + content)
|
||||||
|
|
||||||
|
|
||||||
# count Action
|
# count Action
|
||||||
for out_file in out_files:
|
for out_file in out_files:
|
||||||
Output_File_Path = Output_File_Directory + out_file
|
Output_File_Path = Output_File_Directory + out_file
|
||||||
@ -452,4 +467,3 @@ for out_file in out_files:
|
|||||||
pass
|
pass
|
||||||
print(out_file, count + 1)
|
print(out_file, count + 1)
|
||||||
line_prepender(Output_File_Path, str(count+1))
|
line_prepender(Output_File_Path, str(count+1))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user