LoginSignup
2

More than 5 years have passed since last update.

多段階選抜

Last updated at Posted at 2014-08-03

当日はテストケースがいくつか通らないところがあったのですが、
全く同じロジックで、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])

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2