Problem:


UFO 撃墜作戦

  40XX 年、地球は宇宙人の侵攻を受けていた!すでに地球のほとんどは宇宙人により制圧されており、残る防衛拠点は鶴ヶ城要塞のみになってしまった。その鶴ヶ城要塞にも、制圧部隊が次々に迫ってきている。

  

  しかし、希望は残されている。防衛軍の最終兵器、超長距離貫通レーザー砲が完成したのだ。欠点といえば、   威力が出るまでに一定の距離が必要で、          近すぎる敵はただ通りぬけてしまうということだ。  威力が出ない範囲に侵入した敵は、他の戦力でどうにかするしかない。防衛軍の参謀は、侵入して来た UFO に対処するために、その数を知らなければならないのだが、あまりにも敵が多いせいでうまく数えられそうにない。そこで参謀はあなたに、レーザーに撃墜されなかった UFO の数を出力するプログラムを用意するように命令した。戦闘開始までにプログラムを作成し、鶴ヶ城要塞を守る力となろう。

  敵の UFO はただまっすぐにレーザー砲のある拠点を目指して突撃してくる(UFO には互いにすり抜ける処理が施されており、衝突してしまうことはない) 。レーザー砲は、初期状態から 1 分後に最も近い UFO の中心を狙ってレーザーを発射し始め、それから 1 分ごとに同じ条件でレーザーを発射し続ける。レーザーは貫通し、その先にある UFO もレーザーがかすっただけで撃墜することができる。しかし、このレーザーには威力の出ない範囲があり、その範囲に入ってしまったUFO は狙っても意味がないため、狙わないように設計されている。撃墜できるだけ撃墜したとき、レーザーの威力が出ない範囲には何機の UFO が侵入しただろうか。

  レーザーの威力が出ない範囲の半径 R と、襲来する UFO の情報を入力とし、撃墜されず侵入している UFO が何機いるかを出力するプログラムを作成してください。 襲来する UFO の情報は、UFO の数 N 、各 UFO の初期座標 (x0, y0)、各 UFO の半径 r 、各 UFO の分速 v で構成されます。

  座標の原点 (0 , 0) をレーザー砲の位置とします。レーザー砲と UFO の距離は原点から UFO の中心までの距離で与えられ、この距離が R 以下の UFO はレーザーの威力が出ない範囲に入ったとします。狙うべき対象が同時に複数存在する場合はないものとして考えます。計算は全て平面上で考え、入力はすべて整数で与えられます。

Input

複数のデータセットの並びが入力として与えられます。 入力の終わりはゼロふたつの行で示されます。
各データセットは以下の形式で与えられます。

R N
x01 y01 r1 v1
x02 y02 r2 v2
:
x0N y0N rN vN

1 行目にレーザーの威力が出ない範囲の半径 R (1 ≤ R ≤ 500) とUFO の数 N (1 ≤ N ≤ 100) が与えられます。続く N 行に i 機目の UFO の情報 x0i, y0i (-100 ≤ x0i, y0i ≤ 1000), ri,  vi (1 ≤ ri, vi ≤ 500) が与えられます。

データセットの数は 50 を超えません。

Output

入力データセットごとに、レーザーの威力が出ない範囲に侵入した UFO の数を1行に出力します。

Sample Input

100 5
101 101 5 5
110 110 2 3
-112 -100 9 11
-208 160 82 90
-110 108 10 2
10 11
15 0 5 1
25 0 5 1
35 0 5 1
45 0 5 1
55 0 5 1
65 0 5 1
75 0 5 1
85 0 5 1
95 0 5 1
-20 0 5 20
-30 0 500 5
0 0

Output for the Sample Input

1
1



Sample input:
100 5
101 101 5 5
110 110 2 3
-112 -100 9 11
-208 160 82 90
-110 108 10 2
10 11
15 0 5 1
25 0 5 1
35 0 5 1
45 0 5 1
55 0 5 1
65 0 5 1
75 0 5 1
85 0 5 1
95 0 5 1
-20 0 5 20
-30 0 500 5
0 0


Sample output:
1
1

Submission status: Wrong Answer

Solution code:
import math

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def move(ufos, R):
  remove_lst = []
  for i , ufo in enumerate(ufos):
    ufo[0] -= ufo[3]
    if ufo[0] <= R:
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)
  return len(remove_lst)

def is_dead(ufo, laser):
  dist = ufo[0]
  angle = ufo[1]
  rad = ufo[2]
  diff = abs(angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and math.sin(diff) * dist <= rad) or dist <= rad:
    return True
  else:
    return False

def shoot(ufos, laser):
  remove_lst = []
  for i, ufo in enumerate(ufos):
    if is_dead(ufo, laser):
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)

while True:
  R, n = map(int, input().split())
  if R == 0:
    break

  ufos = []
  for _ in range(n):
    x, y, r, v = map(int, input().split())
    ufos.append([get_dist(x, y), get_angle(x, y), r, v])
  
  ans = 0
  while ufos:
    ans += move(ufos, R)
    if ufos:
      laser = min(ufos)[1]
      shoot(ufos, laser)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def move(ufos):
  for ufo in ufos:
    ufo.dist -= ufo.v

def reache(ufos, R):
  remove_lst = []
  for i , ufo in enumerate(ufos):
    if ufo.dist <= R:
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)
  return len(remove_lst)

def is_dead(ufo, laser):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and math.sin(diff) * ufo.dist <= ufo.rad) or ufo.dist <= ufo.rad:
    return True
  else:
    return False

def shoot(ufos, laser):
  remove_lst = []
  for i, ufo in enumerate(ufos):
    if is_dead(ufo, laser):
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)

while True:
  R, n = map(int, input().split())
  if R == 0:
    break

  ufos = []
  for _ in range(n):
    x, y, r, v = map(int, input().split())
    ufos.append(Ufo(x, y, r, v))
  
  ans = 0
  while ufos:
    move(ufos)
    ans += reache(ufos, R)
    if ufos:
      laser = min(ufos, key=lambda ufo:ufo.dist).angle
      shoot(ufos, laser)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def reache(ufos, R):
  remove_lst = []
  for i , ufo in enumerate(ufos):
    ufo.dist -= ufo.v
    if ufo.dist <= R:
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)
  return len(remove_lst)

def is_dead(ufo, laser):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and math.sin(diff) * ufo.dist <= ufo.rad) or ufo.dist <= ufo.rad:
    if ufo.dist * math.cos(diff) > R:
      return True
  return False

def shoot(ufos, laser):
  remove_lst = []
  for i, ufo in enumerate(ufos):
    if is_dead(ufo, laser):
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)

while True:
  R, n = map(int, input().split())
  if R == 0:
    break

  ufos = []
  for _ in range(n):
    x, y, r, v = map(int, input().split())
    ufos.append(Ufo(x, y, r, v))
  
  ans = 0
  while ufos:
    ans += reache(ufos, R)
    if ufos:
      laser = min(ufos, key=lambda ufo:ufo.dist).angle
      shoot(ufos, laser)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def reache(ufos, R):
  remove_lst = []
  for i , ufo in enumerate(ufos):
    ufo.dist -= ufo.v
    if ufo.dist <= R:
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)
  return len(remove_lst)

def is_dead(ufo, laser, R):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if diff <= math.pi / 2:
    if ufo.dist * math.sin(diff) <= ufo.rad and ufo.dist * math.cos(diff) + (ufo.rad ** 2 - (ufo.dist * math.sin(diff)) ** 2) ** (1 / 2) > R:
      return True
  return False

def shoot(ufos, laser, R):
  remove_lst = []
  for i, ufo in enumerate(ufos):
    if is_dead(ufo, laser, R):
      remove_lst.append(i)
  for i in reversed(remove_lst):
    ufos.pop(i)

while True:
  R, n = map(int, input().split())
  if R == 0:
    break

  ufos = []
  for _ in range(n):
    x, y, r, v = map(int, input().split())
    ufos.append(Ufo(x, y, r, v))
  
  ans = 0
  while ufos:
    ans += reache(ufos, R)
    if ufos:
      laser = min(ufos, key=lambda ufo:ufo.dist).angle
      shoot(ufos, laser, R)
  print(ans)

Submission status: Wrong Answer

Solution code:
import math

class Ufo:
  def __init__(self, x, y, r, v):
    self.dist = get_dist(x, y)
    self.angle = get_angle(y, x)
    self.rad = r
    self.v = v

def get_dist(x, y):
  return (x ** 2 + y ** 2) ** (1 / 2)

def get_angle(x, y):
  angle = math.atan2(y, x)
  if angle < 0:
    angle += math.pi * 2
  return angle

def reach(ufos, R):
  remove_lst = []
  for ufo in ufos:
    ufo.dist -= ufo.v
    if ufo.dist <= R:
      remove_lst.append(ufo)
  for ufo in remove_lst:
    ufos.remove(ufo)
  return len(remove_lst)

def is_dead(ufo, laser, R):
  diff = abs(ufo.angle - laser)
  if diff > math.pi:
    diff = math.pi * 2 - diff
  if (diff <= math.pi / 2 and ufo.dist * math.sin(diff) <= ufo.rad) or (ufo.dist <= ufo.rad):
    if ufo.dist * math.cos(diff) + (ufo.rad ** 2 - (ufo.dist * math.sin(diff)) ** 2) ** (1 / 2) > R:
      return True
  return False

def shoot(ufos, laser, R):
  remove_lst = []
  for ufo in ufos:
    if is_dead(ufo, laser, R):
      remove_lst.append(ufo)
  for ufo in remove_lst:
    ufos.remove(ufo)

def main():
  while True:
    R, n = map(int, input().split())
    if R == 0:
      break
  
    ufos = []
    for _ in range(n):
      x, y, r, v = map(int, input().split())
      ufos.append(Ufo(x, y, r, v))
    
    ans = 0
    while ufos:
      ans += reach(ufos, R)
      if ufos:
        laser = min(ufos, key=lambda ufo:ufo.dist).angle
        shoot(ufos, laser, R)
      print(ans)
main()

Submission status: Wrong Answer

Solution code:
def jgraze(f):
        if (1/s[n])*(u[i][0]-u[i][2])<=u[i][1]-u[i][2]<=(1/s[n])*(u[i][0]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]+u[i][2])<=u[i][1]-u[i][2]<=(1/s[n])*(u[i][0]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]-u[i][2])<=u[i][1]+u[i][2]<=(1/s[n])*(u[i][0]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]+u[i][2])<=u[i][1]+u[i][2]<=(1/s[n])*(u[i][0]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]-u[i][2])<=u[i][0]-u[i][2]<=s[n]*(u[i][1]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]+u[i][2])<=u[i][0]-u[i][2]<=s[n]*(u[i][1]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]-u[i][2])<=u[i][0]+u[i][2]<=s[n]*(u[i][1]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]+u[i][2])<=u[i][0]+u[i][2]<=s[n]*(u[i][1]-u[i][2]):
                u[i][2]=-1
                f+=1
        return f
def jgaxis(f):
        if u[i][0]-u[i][2]<=u[n][0]<=u[i][0]+u[i][2]:
                u[i][2]=-1
                f+=1
        elif u[i][1]-u[i][2]<=u[n][1]<=u[i][1]+u[i][2]:
                u[i][2]=-1
                f+=1
        return f

while 1:
        r=map(int,raw_input().split())
        if r[0]==r[1]==0:
                break
        u=[0 for i in range(r[1])]              # informations of UFOs
        for i in range(r[1]):
                u[i]=map(float,raw_input().split())
        d=[0 for i in range(r[1])]              # distance to UFOs
        for i in range(r[1]):
                d[i]=(u[i][0]**2+u[i][1]**2)**0.5
        s=[0 for i in range(r[1])]              # slope to UFOs
        for i in range(r[1]):
                if u[i][1]!=0:
                        s[i]=u[i][0]/u[i][1]
        p=f=0                                   # passed and finished UFO(s)
        while f<r[1]:
                for i in range(r[1]):
                        if u[i][2]!=-1:
                                n=i
                for i in range(r[1]):
                        if u[i][2]!=-1:         # move UFOs
                                if u[i][0]!=0 and u[i][1]!=0:
                                        if 0<u[i][0]:
                                                u[i][0]-=((u[i][3]**2)/(s[i]**(-2)+1))**0.5
                                        elif u[i][0]<0:
                                                u[i][0]+=((u[i][3]**2)/(s[i]**(-2)+1))**0.5
                                        if 0<u[i][1]:
                                                u[i][1]-=((u[i][3]**2)/(s[i]**2+1))**0.5
                                        elif u[i][1]<0:
                                                u[i][1]+=((u[i][3]**2)/(s[i]**2+1))**0.5
                                else:
                                        if u[i][0]==0 and 0<u[i][1]:
                                                u[i][1]-=u[i][3]
                                        if u[i][0]==0 and u[i][1]<0:
                                                u[i][1]+=u[i][3]
                                        if u[i][1]==0 and 0<u[i][0]:
                                                u[i][0]-=u[i][3]
                                        if u[i][1]==0 and u[i][0]<0:
                                                u[i][0]+=u[i][3]
                                d[i]=(u[i][0]**2+u[i][1]**2)**0.5
                                if d[i]<=r[0]:  # process passed UFO
                                        u[i][2]=-1
                                        p+=1
                                        f+=1
                                elif r[0]<d[i]<d[n]:
                                        n=i     # process nearest UFO
                for i in range(r[1]):           # process grazed laser
                        if u[i][2]!=-1:
                                print i
                                if 0<u[n][0] and 0<u[i][0]:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgraze(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgraze(f))
                                        elif u[i][1]==0:
                                                f=int(jgaxis(f))
                                elif u[n][0]<0 and u[i][0]<0:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgraze(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgraze(f))
                                        elif u[i][1]==0:
                                                f=int(jgaxis(f))
                                elif u[n][0]==0:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgaxis(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgaxis(f))
        print p

Submission status: Wrong Answer

Solution code:
def jgraze(f):
        if (1/s[n])*(u[i][0]-u[i][2])<=u[i][1]-u[i][2]<=(1/s[n])*(u[i][0]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]+u[i][2])<=u[i][1]-u[i][2]<=(1/s[n])*(u[i][0]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]-u[i][2])<=u[i][1]+u[i][2]<=(1/s[n])*(u[i][0]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif (1/s[n])*(u[i][0]+u[i][2])<=u[i][1]+u[i][2]<=(1/s[n])*(u[i][0]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]-u[i][2])<=u[i][0]-u[i][2]<=s[n]*(u[i][1]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]+u[i][2])<=u[i][0]-u[i][2]<=s[n]*(u[i][1]-u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]-u[i][2])<=u[i][0]+u[i][2]<=s[n]*(u[i][1]+u[i][2]):
                u[i][2]=-1
                f+=1
        elif s[n]*(u[i][1]+u[i][2])<=u[i][0]+u[i][2]<=s[n]*(u[i][1]-u[i][2]):
                u[i][2]=-1
                f+=1
        return f

def jgaxis(f):
        if u[i][0]-u[i][2]<=u[n][0]<=u[i][0]+u[i][2]:
                u[i][2]=-1
                f+=1
        elif u[i][1]-u[i][2]<=u[n][1]<=u[i][1]+u[i][2]:
                u[i][2]=-1
                f+=1
        return f

while 1:
        r=map(int,raw_input().split())
        if r[0]==r[1]==0:
                break
        u=[0 for i in range(r[1])]              # informations of UFOs
        for i in range(r[1]):
                u[i]=map(float,raw_input().split())
        d=[0 for i in range(r[1])]              # distance to UFOs
        for i in range(r[1]):
                d[i]=(u[i][0]**2+u[i][1]**2)**0.5
        s=[0 for i in range(r[1])]              # slope to UFOs
        for i in range(r[1]):
                if u[i][1]!=0:
                        s[i]=u[i][0]/u[i][1]
        p=f=0                                   # passed and finished UFO(s)
        while f<r[1]:
                for i in range(r[1]):
                        if u[i][2]!=-1:
                                n=i
                for i in range(r[1]):
                        if u[i][2]!=-1:         # move UFOs
                                if u[i][0]!=0 and u[i][1]!=0:
                                        if 0<u[i][0]:
                                                u[i][0]-=((u[i][3]**2)/(s[i]**(-2)+1))**0.5
                                        elif u[i][0]<0:
                                                u[i][0]+=((u[i][3]**2)/(s[i]**(-2)+1))**0.5
                                        if 0<u[i][1]:
                                                u[i][1]-=((u[i][3]**2)/(s[i]**2+1))**0.5
                                        elif u[i][1]<0:
                                                u[i][1]+=((u[i][3]**2)/(s[i]**2+1))**0.5
                                else:
                                        if u[i][0]==0 and 0<u[i][1]:
                                                u[i][1]-=u[i][3]
                                        if u[i][0]==0 and u[i][1]<0:
                                                u[i][1]+=u[i][3]
                                        if u[i][1]==0 and 0<u[i][0]:
                                                u[i][0]-=u[i][3]
                                        if u[i][1]==0 and u[i][0]<0:
                                                u[i][0]+=u[i][3]
                                d[i]=(u[i][0]**2+u[i][1]**2)**0.5
                                if d[i]<=r[0]:  # process passed UFO
                                        u[i][2]=-1
                                        p+=1
                                        f+=1
                                elif r[0]<d[i]<d[n]:
                                        n=i     # process nearest UFO
                for i in range(r[1]):           # process grazed laser
                        if u[i][2]!=-1:
                                if 0<u[n][0] and 0<u[i][0]:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgraze(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgraze(f))
                                        elif u[i][1]==0:
                                                f=int(jgaxis(f))
                                elif u[n][0]<0 and u[i][0]<0:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgraze(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgraze(f))
                                        elif u[i][1]==0:
                                                f=int(jgaxis(f))
                                elif u[n][0]==0:
                                        if 0<u[n][1] and 0<u[i][1]:
                                                f=int(jgaxis(f))
                                        elif u[n][1]<0 and u[i][1]<0:
                                                f=int(jgaxis(f))
        print p

Submission status: Wrong Answer

Solution code:
from sys import stdin
from math import sqrt,fabs

class Game:
	class Ufo:
		def __init__(self,x,y,r,v):
			self.x = x*1.0
			self.y = y*1.0
			self.r = r*1.0
			self.v = v*1.0
			self.d = sqrt(x**2+y**2)
			self.cs = self.x / self.d
			self.si = self.y / self.d
			self.vx = -self.v*self.cs
			self.vy = -self.v*self.si

		def __str__(self):
			return "ufo x = " + str(self.x) + ", y = " + str(self.y) + ", r = " + str(self.r) + ", v = " + str(self.v)

		def oneMinMove(self):
			self.x += self.vx
			self.y += self.vy
			self.d -= self.v

	class Laser:
		def __init__(self,cs,si):
			self.cs = cs
			self.si = si

	ufos = []
	laser = Laser(0,0)
	gameend = False
	inrl = 0
	def __init__(self,R):
		self.R = R

	def hit(self,laser,ufo):
		temp1 = ufo.r**2 - (laser.si*ufo.x - laser.cs*ufo.y)**2
		if temp1 >= 0:
			temp2 = laser.cs*ufo.x + laser.si*ufo.y
			d1 = temp2 + sqrt(temp1)
			d2 = temp2 - sqrt(temp1)
			if d1>=0 or d2>=0: return True
			else: return False
		else: return False

	def isInvaded(self,ufo):
		return (ufo.d<= self.R)
	
	def gameOneMinMove(self):
		curInrs = []
		for ufo in self.ufos:
			ufo.oneMinMove()
			if self.isInvaded(ufo): curInrs.append(ufo)
		self.inrl += len(curInrs)
		#print str(len(curInrs)) + " ufos invaded!"
		for ufo in curInrs:
			self.ufos.remove(ufo)
			#print ufo
		del curInrs
		if self.ufos == []:
			self.gameend = True

	def setLaser(self):
		nearestUfo = self.ufos[0]
		for ufo in self.ufos:
			if nearestUfo.d > ufo.d :
				nearestUfo = ufo
		self.laser = self.Laser(nearestUfo.cs,nearestUfo.si)

	def fireLaser(self):
		curDeads = []
		for ufo in self.ufos:
			if self.hit(self.laser,ufo):
				curDeads.append(ufo)
		#print str(len(curDeads)) +" ufos burned!"
		for ufo in curDeads:
			self.ufos.remove(ufo)
			#print ufo
		del curDeads

	def oneLogic(self):
		self.gameOneMinMove()
		if self.gameend:
			pass
		else:
			self.setLaser()
			self.fireLaser()

	def allLogic(self):
		while not self.gameend:
			self.oneLogic()


for inp in stdin:
#for inp in open("input.txt"):
	try:
		inp = map(int,inp.split())
		if len(inp) == 2:
			if inp == (0,0): break
			game = Game(inp[0])
			N = inp[1]
		else:
			game.ufos.append(game.Ufo(inp[0],inp[1],inp[2],inp[3]))
			if len(game.ufos) == N:
				game.allLogic()
				print game.inrl
	except:
		break

Submission status: Wrong Answer

Solution code:
from math import sqrt,fabs

class Ufo:
    def __init__(self,x,y,r,v):
        self.x = x*1.0
        self.y = y*1.0
        self.r = r*1.0
        self.v = v*1.0
        self.d = sqrt(x**2+y**2)
        self.cs = self.x / self.d
        self.si = self.y / self.d
        self.vx = -self.v*self.cs
        self.vy = -self.v*self.si

    def __str__(self):
        return "ufo x = " + str(self.x) + ", y = " + str(self.y) + ", r = " + str(self.r) + ", v = " + str(self.v)

    def oneMinMove(self):
        self.x += self.vx
        self.y += self.vy
        self.d -= self.v

    def isInvaded(self):
        return (self.d<= game.R)


class Laser:
    def __init__(self,cs,si):
        self.cs = cs
        self.si = si

    def hit(self,ufo):
        temp1 = ufo.r**2 - (self.si*ufo.x - self.cs*ufo.y)**2
        if temp1 >= 0:
            temp2 = self.cs*ufo.x + self.si*ufo.y
            d1 = temp2 + sqrt(temp1)
            d2 = temp2 - sqrt(temp1)
            if d1>=0 or d2>=0: return True
            else: return False
        else: return False


class Game:
    ufos = []
    laser = Laser(0,0)
    gameend = False
    inrl = 0
    def __init__(self,R):
        self.R = R

    def gameOneMinMove(self):
        curInrs = []
        for ufo in self.ufos:
            ufo.oneMinMove()
            if ufo.isInvaded(): curInrs.append(ufo)
        self.inrl += len(curInrs)
        #print str(len(curInrs)) + " ufos invaded!"
        for ufo in curInrs:
            self.ufos.remove(ufo)
            #print ufo
        del curInrs
        if self.ufos == []:
            self.gameend = True

    def setLaser(self):
        nearestUfo = self.ufos[0]
        for ufo in self.ufos:
            if nearestUfo.d > ufo.d :
                nearestUfo = ufo
        self.laser = Laser(nearestUfo.cs,nearestUfo.si)

    def fireLaser(self):
        curDeads = []
        for ufo in self.ufos:
            if self.laser.hit(ufo):
                curDeads.append(ufo)
        #print str(len(curDeads)) +" ufos burned!"
        for ufo in curDeads:
            self.ufos.remove(ufo)
            #print ufo
        del curDeads

    def oneLogic(self):
        self.gameOneMinMove()
        if self.gameend:
            pass
        else:
            self.setLaser()
            self.fireLaser()

    def allLogic(self):
        while not self.gameend:
            self.oneLogic()


while True:
    inp = map(int,raw_input().split())
    if inp == [0,0]: break
    if len(inp) == 2:
        game = Game(inp[0])
        N = inp[1]
    else:
        game.ufos.append(Ufo(inp[0],inp[1],inp[2],inp[3]))
        if len(game.ufos) == N:
            game.allLogic()
            print game.inrl

Submission status: Wrong Answer

Solution code:
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/int((a**2+b**2)**0.5)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			ufos[i].append((ufos[i][0]**2+ufos[i][1]**2)**0.5)
		#ufos[i]=[x,y,r,v,d]
		invade=0
		while ufos:
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
	
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
					
			target=sorted(ufos,key=lambda i:i[4]).pop(0)
			a,b=target[1],-target[0]
	
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/int((a**2+b**2)**0.5)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			ufos[i].append((ufos[i][0]**2+ufos[i][1]**2)**0.5)
		#ufos[i]=[x,y,r,v,d]
		invade=0
		while ufos:
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
	
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			
			ufos=sorted(ufos,key=lambda i:i[4])		
			target=ufos.pop(0)
			a,b=target[1],-target[0]
				
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/(a**2+b**2)**0.5
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			ufos[i].append((ufos[i][0]**2+ufos[i][1]**2)**0.5)
		#ufos[i]=[x,y,r,v,d]
		invade=0
		while ufos:
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
	
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			
			ufos=sorted(ufos,key=lambda i:i[4])
			target=ufos.pop(0)
			a,b=target[1],-target[0]
			
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
import math
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/math.sqrt(a**2+b**2)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			ufos[i].append(math.sqrt(ufos[i][0]**2+ufos[i][1]**2))
			ufos[i].append(ufos[i][0]/ufos[i][4])
			ufos[i].append(ufos[i][1]/ufos[i][4])
		#ufos[i]=[x,y,r,v,d,sin,cos]
		invade=0
		while ufos:
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
				ufos[i][0]=ufos[i][4]*ufos[i][0]
				ufos[i][1]=ufos[i][4]*ufos[i][1]
				
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			
			ufos=sorted(ufos,key=lambda i:i[4])
			target=ufos.pop(0)
			a,b=target[1],-target[0]
			
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
#try-except is necessary. If there is not try-except, Runtime error happens.
import math
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/math.sqrt(a**2+b**2)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			ufos[i].append(math.sqrt(ufos[i][0]**2+ufos[i][1]**2))
			ufos[i].append(ufos[i][0]/ufos[i][4])
			ufos[i].append(ufos[i][1]/ufos[i][4])
		#ufos[i]=[x,y,r,v,d,sin,cos]
		invade=0
		while ufos:
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
				ufos[i][0]=ufos[i][4]*ufos[i][5]
				ufos[i][1]=ufos[i][4]*ufos[i][6]
				
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			
			ufos=sorted(ufos,key=lambda i:i[4])
			target=ufos.pop(0)
			a,b=target[1],-target[0]
			
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
#try-except is necessary. If there is not try-except, Runtime error happens.
import math
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/math.sqrt(a**2+b**2)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			#append d,sin,cos
			ufos[i].append(math.sqrt(ufos[i][0]**2+ufos[i][1]**2))
			ufos[i].append(ufos[i][0]/ufos[i][4])
			ufos[i].append(ufos[i][1]/ufos[i][4])
		#ufos[i]=[x,y,r,v,d,sin,cos]
		invade=0
		while ufos:
			# update d,x,y
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
				ufos[i][0]=ufos[i][4]*ufos[i][5]
				ufos[i][1]=ufos[i][4]*ufos[i][6]
			# remove ufo r<=R
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			# remove nearest ufo
			ufos=sorted(ufos,key=lambda i:i[4])
			target=ufos.pop(0)
			a,b=target[1],-target[0]
			# remove ufo that laser hits
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
#try-except is necessary. If there is not try-except, Runtime error happens.
import math
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/math.sqrt(a**2+b**2)
	return True if D<=ufo[2] else False

while 1:
	try:
		R,N=map(int,raw_input().split())
		if R==0:break
		ufos=[map(int,raw_input().split()) for i in range(N)]
		for i in range(N):
			#append d,cos,sin
			ufos[i].append(math.sqrt(ufos[i][0]**2+ufos[i][1]**2))
			ufos[i].append(ufos[i][0]/ufos[i][4])
			ufos[i].append(ufos[i][1]/ufos[i][4])
		#ufos[i]=[x,y,r,v,d,cos,sin]
		invade=0
		while ufos:
			# update d,x,y
			for i in range(len(ufos)):
				ufos[i][4]-=ufos[i][3]
				ufos[i][0]=ufos[i][4]*ufos[i][5]
				ufos[i][1]=ufos[i][4]*ufos[i][6]
			# remove ufo d<=R
			for i in range(len(ufos)-1,-1,-1):
				if ufos[i][4]<=R:
					invade+=1
					ufos.pop(i)
			if len(ufos)==0:break
			# remove nearest ufo
			ufos=sorted(ufos,key=lambda i:i[4])
			target=ufos.pop(0)
			a,b=target[1],-target[0]
			# remove ufo that laser hits
			for i in range(len(ufos)-1,-1,-1):
				if isHit(a,b,ufos[i]):
					ufos.pop(i)
					
		print invade
	except:
		pass

Submission status: Wrong Answer

Solution code:
#try-except is necessary. If there is not try-except, Runtime error happens.
import math
def isHit(a,b,ufo):
	D=abs(a*ufo[0]+b*ufo[1])/math.sqrt(a**2+b**2)
	return True if D<=ufo[2] else False

while 1:
	R,N=map(int,raw_input().split())
	if R==0:break
	ufos=[map(int,raw_input().split()) for i in range(N)]
	for i in range(N):
		#append d,cos,sin
		ufos[i].append(math.sqrt(ufos[i][0]**2+ufos[i][1]**2))
		ufos[i].append(ufos[i][0]/ufos[i][4])
		ufos[i].append(ufos[i][1]/ufos[i][4])
	#ufos[i]=[x,y,r,v,d,cos,sin]
	invade=0
	while ufos:
		# update d,x,y
		for i in range(len(ufos)):
			ufos[i][4]-=ufos[i][3]
			ufos[i][0]=ufos[i][4]*ufos[i][5]
			ufos[i][1]=ufos[i][4]*ufos[i][6]
		# remove ufo d<=R
		for i in range(len(ufos)-1,-1,-1):
			if ufos[i][4]<=R:
				invade+=1
				ufos.pop(i)
		if len(ufos)==0:break
		# remove nearest ufo
		ufos=sorted(ufos,key=lambda i:i[4])
		target=ufos.pop(0)
		a,b=target[1],-target[0]
		# remove ufo that laser hits
		for i in range(len(ufos)-1,-1,-1):
			if isHit(a,b,ufos[i]):
				ufos.pop(i)
				
	print invade