多段階選抜
当日はテストケースがいくつか通らないところがあったのですが、
全く同じロジックで、Pythonで書き直したところテストが通りました。
(Rubyで動かなかったのがまだ原因突き止められず^^;)
問題は以下URL
http://nabetani.sakura.ne.jp/hena/ord24eliseq/
# -*- coding: utf-8 -*-
import sys
import math
from scipy.special import cbrt
from string import rstrip
max = 10000
sqrts = []
cbrts = []
for i in range(1,max):
if math.sqrt(i) - int(math.sqrt(i)) == 0:
sqrts.append(i)
if cbrt(i) - int(cbrt(i)) == 0:
cbrts.append(i)
if __name__ == '__main__':
while True:
input = list(sys.stdin.readline().rstrip())
ret = range(1,max)
for x in input:
count = 0
tmp = list(ret)
if x == 'S':
for r in ret:
for s in sqrts:
if r == s:
tmp[count + 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 's':
for r in ret:
for s in sqrts:
if r == s:
tmp[count - 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'C':
for r in ret:
for s in cbrts:
if r == s:
tmp[count + 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'c':
for r in ret:
for s in cbrts:
if r == s:
tmp[count - 1] = None
count += 1
ret = []
for y in tmp:
if y is not None:
ret.append(y)
elif x == 'h':
ret = ret[100:]
else:
for y in range(0,len(ret),int(x)):
tmp[y-1] = None
ret = []
for y in tmp:
if y is not None:
ret.append(y)
print ','.join(str(x) for x in ret[0:10])
Author And Source
この問題について(多段階選抜), 我々は、より多くの情報をここで見つけました https://qiita.com/sakaitaka/items/00f8a35eee0a1ba9b296著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .