无聊之时,为了不让自己的程序技术荒废,在学习数学之余,我又来参加比赛。截至到刚才不久,线上练习结束开始正式进入初赛,这是我的成绩 只能说我已经尽力了,在武长(湖北+湖南)区至少进入了一半以内,由于只有32以前才能进复赛,我看来一下,大概280多万,差了100万左右,初赛也不想搞了,就在下面放出代码。
[00:00.000] 作词 : Ayumi
[00:00.000] 作曲 : 柳英一郎
[00:16.024]影絵のよう 揺れる記憶
[00:23.001]差し伸べた右手
[00:29.082]縋るように
[00:33.027]求めていた 一筋の光
[00:46.094]閉ざされてた鏡の中
[00:53.086]自分を探して  消えた世界
[01:04.015]そこにどんな夢を見ていたの?
[01:14.031]どうか抱いていて明日への希望を
[01:28.009]閉ざされた未来はトンネルの先へ
[01:51.096]叫ぶことに意味はなくて
[01:58.095]零れた涙と
[02:05.044]ねぇ、聞こえる?
[02:08.099]あの日見てた「幸せ」の意味を
[02:19.020]ずっと信じてた色褪せた奇跡を
[02:32.090]回らない風車が溶かして約束
[02:47.030]……
[00:00.000]編曲 クサノユウキfrom SYRIKERS
[03:21.053]……
[03:24.095]ずっと信じてた色褪せた奇跡を
[03:38.050]回らない風車が溶かして約束
[03:52.020]どうか
[03:55.051]どうかただ
[03:58.096]そばにいて欲しいと Ah
[04:05.080]手探りで願った
[04:12.065]果てなき罪へと

无聊之时,为了不让自己的程序技术荒废,在学习数学之余,我又来参加比赛。截至到刚才不久,线上练习结束开始正式进入初赛,这是我的成绩

只能说我已经尽力了,在武长(湖北+湖南)区至少进入了一半以内,由于只有32以前才能进复赛,我看来一下,大概280多万,差了100万左右,初赛也不想搞了,就在下面放出代码。

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/bash
import sys
import math

# GetMapData
def readMap():
cache = [input()]
while cache[-1] != "OK":
cache.append(input())
return ''.join(cache[0:-1])
# Output Over
def finish():
sys.stdout.write('OK\n')
sys.stdout.flush()
# Constant
totalTime = 3*60
mapSquare = 50*50
robotNum = 4
framePerMin = 50
initMoney = 200000
maxLinearV = 6.0
maxAngularV = math.pi
# GetFrameData
def readInput():
inputData = {}
inputData["wbNum"] = int(input())
inputData["wb"] = []
for i in range(0,inputData["wbNum"]):
inputData["wb"].append(input().split(' '))
inputData['rStatus'] = []
inputData['rStatus'].append(input().split(' '))
while inputData['rStatus'][-1][0] != "OK":
inputData['rStatus'].append(input().split(' '))
inputData['rStatus'].pop()
return inputData

##########通用代码##########
# 存在4层分级
# 优先级自上而下
# 顶:8
# 1层:7
# 2层:4,5,6
# 低:1,2,3
wbAbility = {
'1':[0, 50, 1],
'2':[0, 50, 2],
'3':[0, 50, 3],
'4':[[1,2], 500, 4],
'5':[[1,3], 500, 5],
'6':[[2,3], 500, 6],
'7':[[4,5,6], 1000, 7],
'8':[[7], 1, 0],
'9':[[1,2,3,4,5,6,7], 1, 0]}
def isSameWB(wb1, wb2):
if wb1[1]==wb2[1] and wb1[2]==wb2[2]:
return True
else:
return False
def getDiatance(x1,y1,x2,y2):
return (float(x1)-float(x2))**2+(float(y1)-float(y2))**2
def getClosestWB(robot, wb):
curInd = wb[0]
curDis = 5000
for curWb in wb:
tmp = getDiatance(robot[8], robot[9], curWb[1], curWb[2])
if curDis > tmp:
curDis = tmp
curInd = curWb
return curInd
def getAngleOffset(source, target):
if source >= 0:
myAngle = source
else:
myAngle = source + 2*math.pi
angle = myAngle - target
if abs(angle) <= math.pi:
return angle
if angle > 0:
return angle-2*math.pi
else:
return angle+2*math.pi
def getToDisSpeed(robot, wb):
# 处理角速度
angularV = 0.0
if abs(float(robot[8])-float(wb[1]))<1e-5:
if float(robot[9])<float(wb[2]): # 向上
offsetA = getAngleOffset(float(robot[7]), math.pi/2)
else: # 向下
offsetA = getAngleOffset(float(robot[7]), math.pi*3/2)
else:
valueOf = math.atan((float(robot[9])-float(wb[2]))/(float(robot[8])-float(wb[1])))
if float(robot[8]) > float(wb[1]): # 向左
valueOf = valueOf + math.pi
else: # 向右
pass
if valueOf < 0:
valueOf = valueOf + 2*math.pi
offsetA = getAngleOffset(float(robot[7]), valueOf)
if abs(offsetA)<1e-5:
angularV = offsetA
else:
if offsetA > 0:
angularV = -maxAngularV
else:
angularV = maxAngularV
# sys.stderr.write("offsetA:%f angularV:%f\n"%(offsetA, angularV))
# 处理线速度
linearV = 0.0
dis = math.sqrt(getDiatance(robot[8], robot[9], wb[1], wb[2]))
if dis < 1.0:
linearV = maxLinearV*dis
else:
linearV = maxLinearV
return angularV,linearV
def isWbEmpty(wbN, pos):
if ((int(wbN) >> pos)&1) == 0:
return True
else:
return False
def isSellToWb(wb, pos):
if wb[0] in ['1','2','3']:
return False
if (int(pos) in wbAbility[wb[0]][0]) and isWbEmpty(wb[4], int(pos)):
return True
return False

##########核心代码##########
def computeTheCommandWithNine(frameData):
return computeTheCommand(frameData)
##########不带9号###########
#####################
# FrameData 字典
# wbNum 工作台个数
# wb 工作台List
# rStatus 机器人List
#####################
def computeTheCommand(frameData):
# 工作台梯队获取
de1 = list(filter(lambda x: x[0]=='8', frameData["wb"]))
de2 = list(filter(lambda x: x[0]=='7', frameData["wb"]))
de3 = list(filter(lambda x: x[0] in ['4','5','6'], frameData["wb"]))
de4 = list(filter(lambda x: x[0] in ['1','2','3'], frameData["wb"]))

tmpde2 = list(filter(lambda x: x[5]=='1', de2))
tmpde3 = list(filter(lambda x: x[5]=='1', de3))
tmpde4 = list(filter(lambda x: x[5]=='1', de4))

# 资源空缺的统计 de2、de3
theRequirement = [0,0,0,0,0,0,0]
for wb in (de2+de3):
for pos in wbAbility[wb[0]][0]:
if isWbEmpty(wb[4], pos):
theRequirement[pos] = theRequirement[pos] + 1
# 派遣情况
assignmnet = [0,0,0,0]

# 指令集
command = []
# 机器人轮流查询,第一轮
for ind,curRob in enumerate(frameData["rStatus"]):
# 能卖则卖
if curRob[0]!='-1' and curRob[1]!='0' and isSellToWb(frameData["wb"][int(curRob[0])], curRob[1]):
command.append(['sell', ind])
continue
# 非空闲机器人 专注于de1、de2、de3
if curRob[1]!='0':
if curRob[1]=='7':
closeDis = getClosestWB(curRob, de1)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
elif curRob[1] in ['4','5','6']:
tmp = list(filter(lambda x: isSellToWb(x, curRob[1]), de2))
if len(tmp)!=0:
closeDis = getClosestWB(curRob, tmp)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[int(curRob[1])] = theRequirement[int(curRob[1])] - 1
elif curRob[1] in ['3','2','1']:
tmp = list(filter(lambda x: isSellToWb(x, curRob[1]), de3))
if len(tmp)!=0:
closeDis = getClosestWB(curRob, tmp)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[int(curRob[1])] = theRequirement[int(curRob[1])] - 1
# 机器人轮流查询,第二轮
for ind,curRob in enumerate(frameData["rStatus"]):
# 能买则买
if curRob[0]!='-1' and curRob[1]=='0' and frameData["wb"][int(curRob[0])][5]=='1':
tmpWb = frameData["wb"][int(curRob[0])]
if wbAbility[tmpWb[0]][2] == 7:
command.append(['buy', ind])
continue
elif theRequirement[wbAbility[tmpWb[0]][2]] > 0:
command.append(['buy', ind])
continue
# 空闲机器人 专注于de2、de3、de4
if curRob[1]=='0':
if len(tmpde2) != 0:
closeDis = getClosestWB(curRob, tmpde2)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
elif len(tmpde3) != 0:
closeDis = getClosestWB(curRob, tmpde3)
if theRequirement[wbAbility[closeDis[0]][2]] <= 0:
continue
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[wbAbility[closeDis[0]][2]] = theRequirement[wbAbility[closeDis[0]][2]] - 1
elif len(tmpde4) != 0:
closeDis = getClosestWB(curRob, tmpde4)
if theRequirement[wbAbility[closeDis[0]][2]] <= 0:
continue
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[wbAbility[closeDis[0]][2]] = theRequirement[wbAbility[closeDis[0]][2]] - 1
# 机器人轮流查询,第三轮
for ind,curRob in enumerate(frameData["rStatus"]):
# 空闲机器人 按需选择
if assignmnet[ind] == 0:
if len(tmpde3) != 0 or len(tmpde4) != 0:
needMa = []
for posInd, num in enumerate(theRequirement):
if num > 0:
needMa.append(posInd)
tmpde34 = list(filter(lambda x: wbAbility[x[0]][2] in needMa, tmpde3))
if len(tmpde34) != 0:
closeDis = getClosestWB(curRob, tmpde34)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[wbAbility[closeDis[0]][2]] = theRequirement[wbAbility[closeDis[0]][2]] - 1
else:
tmpde34 = list(filter(lambda x: wbAbility[x[0]][2] in needMa, tmpde4))
if len(tmpde34) != 0:
closeDis = getClosestWB(curRob, tmpde34)
tmpAS,tmpLS = getToDisSpeed(curRob, closeDis)
command.append(['forward', ind, tmpLS])
command.append(['rotate', ind, tmpAS])
assignmnet[ind] = closeDis
theRequirement[wbAbility[closeDis[0]][2]] = theRequirement[wbAbility[closeDis[0]][2]] - 1
# sys.stderr.write(str(theRequirement)+'\n')
return command

###########################

if __name__ == '__main__':
# 获取地图
mapData = readMap()
if '9' in mapData:
isNineExist = True
else:
isNineExist = False
finish()
while True:
# 读取数据
line = sys.stdin.readline()
if not line:
break
parts = line.split(' ')
frameId = int(parts[0])
curMoney = int(parts[1])
data = readInput()

# 调度开始
if isNineExist:
command = computeTheCommandWithNine(data)
else:
command = computeTheCommand(data)
# sys.stderr.write(str(command)+"\n")
# 输出数据
sys.stdout.write('%d\n' % frameId)
for oneCom in command:
if oneCom[0] == 'forward':
sys.stdout.write('forward %d %d\n' % (oneCom[1], oneCom[2]))
elif oneCom[0] == 'rotate':
sys.stdout.write('rotate %d %f\n' % (oneCom[1], oneCom[2]))
elif oneCom[0] == 'buy':
sys.stdout.write('buy %d\n' % (oneCom[1]))
elif oneCom[0] == 'sell':
sys.stdout.write('sell %d\n' % (oneCom[1]))
elif oneCom[0] == 'destroy':
sys.stdout.write('destroy %d\n' % (oneCom[1]))
finish()

为什么用Python呢?只是因为看不到进复赛的希望,就抱着试试的心理随便搞了搞。我去年参加过类似的比赛,对手里面是高校的在校生,也就是说还包括研究生,我一个本科生去挑战还是差了点意思。