fork download
  1. #堀江伸一会津大学オンラインジャッジ問0265 Cats Going Straightに挑戦するコード
  2. #少し難しい問題なので気が向いた日に少しずつ記述する
  3. #まだ書き始めこの問題難しいのに36人も合格してるのか
  4. #Ruby言語で合格してる人はいない様子、私が最初のRuby言語での合格者を目指す
  5. def g(x1,y1,x2,y2)
  6. return x1*y2-x2*y1
  7. end
  8.  
  9. def f2(x1,y1,x2,y2,x3,y3,x4,y4)
  10. res=[]
  11. if 0<g(x4,y4,x1,y1) || 0<g(x2,y2,x3,y3) then
  12. return res
  13. end
  14.  
  15.  
  16. end
  17. def f(n)
  18. xs=[]
  19. ys=[]
  20. n.times{|i|
  21. x,y=gets.split(" ").map{|e| e.to_i}
  22. xs<<x
  23. ys<<y
  24. }
  25. n.times{|i|
  26. xs2=[0]*n
  27. ys2=[0]*n
  28. n.times{|j|
  29. p1=(i+j)%n
  30. xs2[p1]=xs[p1]-xs[i]
  31. ys2[p1]=ys[p1]-ys[i]
  32. }
  33. lx=[0]*n
  34. ly=[0]*n
  35. rx=[0]*n
  36. ry=[0]*n
  37. x=xs2[(i+1)%n]
  38. y=ys2[(i+1)%n]
  39. 1.upto(n-2){|j|
  40. p1=(i+j)%n
  41. if 0<g(x,y,xs2[p1],ys2[p1]) then
  42. x=xs2[p1]
  43. y=ys2[p1]
  44. end
  45. lx[p1]=x
  46. ly[p1]=y
  47. }
  48. x=xs2[(i+n-1)%n]
  49. y=ys2[(i+n-1)%n]
  50. 2.upto(n-1){|j|
  51. p1=(i+n-j)%n
  52. p2=(p1+1)%n
  53. if g(x,y,xs2[p2],ys2[p2])<0 then
  54. x=xs2[p2]
  55. y=ys2[p2]
  56. end
  57. rx[p1]=x
  58. ry[p1]=y
  59. }
  60. hsNow={}
  61. }
  62.  
  63. end
  64.  
  65. while true
  66. n=gets.to_i
  67. break if n==0
  68. f(n)
  69. end
Success #stdin #stdout 0.01s 8072KB
stdin
8
0 0
3 2
6 2
8 6
6 5
7 7
0 4
3 4
0
stdout
Standard output is empty