problem_id
stringlengths 6
6
| buggy_code
stringlengths 8
526k
| fixed_code
stringlengths 12
526k
| labels
listlengths 0
15
⌀ | buggy_submission_id
int64 1
1.54M
| fixed_submission_id
int64 2
1.54M
| user_id
stringlengths 10
10
| language
stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02278
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
t = []
n.times do |i|
t << arr.shift
end
# swap????????????
def swap(list, idx1, idx2)
list[idx1], list[idx2] = list[idx2], list[idx1]
return list
end
def minCostPath(list)
sorted = list.sort
total = 0
# list?????????
list.size.times do |i|
# ???????????????????????????????????????????????£?????????
idx1 =sorted[i]
# ??????????????????????????????????±??????????index????????£?????????
idx2 = list.index idx1
n = 0
while idx2 > i
# ??????????????????
n += 1
sortedidx = list.index sorted[idx2]
total += list[sortedidx]
list = swap(list, idx2, sortedidx)
idx2 = sortedidx
end
total += [idx1 * n, idx2*2+sorted[0]*(n+2)].min
end
return total
end
total = minCostPath(t)
p total
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
t = []
n.times do |i|
t << arr.shift
end
# swap????????????
def swap(list, idx1, idx2)
list[idx1], list[idx2] = list[idx2], list[idx1]
return list
end
def minCostPath(list)
sorted = list.sort
total = 0
# list?????????
list.size.times do |i|
# ???????????????????????????????????????????????£?????????
idx1 =sorted[i]
# ??????????????????????????????????±??????????index????????£?????????
idx2 = list.index idx1
n = 0
while idx2 > i
# ??????????????????
n += 1
sortedidx = list.index sorted[idx2]
total += list[sortedidx]
list = swap(list, idx2, sortedidx)
idx2 = sortedidx
end
total += [idx1 * n, idx1*2+sorted[0]*(n+2)].min
end
return total
end
total = minCostPath(t)
p total
|
[
"identifier.change"
] | 121,609
| 121,608
|
u888846141
|
ruby
|
p02279
|
n = gets.to_i
# クラスってかこの程度なら構造体で充分なんだがな!!!!!!!!!!!!!!!!!!!!!!!!!!!
class Tree
attr_accessor :id, :parent, :depth, :tree_type, :childs
def initialize
@childs = []
@parent = -1
@depth = 0
end
end
trees = {}
# 数がわかっているので初期化
n.times do |i|
tree = Tree.new()
tree.id = i
trees[i] = tree
end
# 単にdepthを深くしていくやつ
def rec(par, childs, target)
if childs.size > 0
childs.each do |c|
target[c].parent = par
target[c].depth = target[par].depth + 1
rec(c, target[c].childs, target)
end
end
end
n.times do
t = gets.chomp.split.map(&:to_i)
myid = t[0]
mychilds = []
if t[1] > 0
mychilds = t[2, t[1]]
end
trees[myid].childs = mychilds
# 再帰的にdepthとparentを更新
rec(myid, mychilds, trees)
end
# root、internal node、leaf
trees.each do |t|
if t[1].id.zero?
t[1].tree_type = "root"
elsif t[1].childs.size.zero?
t[1].tree_type = "leaf"
else
t[1].tree_type = "internal node"
end
end
# 出力
n.times do |i|
puts "node #{trees[i].id}: parent = #{trees[i].parent}, depth = #{trees[i].depth}, #{trees[i].tree_type}, [#{trees[i].childs.map(&:to_s).join(', ')}]"
end
|
n = gets.to_i
# クラスってかこの程度なら構造体で充分なんだがな!!!!!!!!!!!!!!!!!!!!!!!!!!!
class Tree
attr_accessor :id, :parent, :depth, :tree_type, :childs
def initialize
@childs = []
@parent = -1
@depth = 0
end
end
trees = {}
# 数がわかっているので初期化
n.times do |i|
tree = Tree.new()
tree.id = i
trees[i] = tree
end
# 単にdepthを深くしていくやつ
def rec(par, childs, target)
if childs.size > 0
childs.each do |c|
target[c].parent = par
target[c].depth = target[par].depth + 1
rec(c, target[c].childs, target)
end
end
end
n.times do
t = gets.chomp.split.map(&:to_i)
myid = t[0]
mychilds = []
if t[1] > 0
mychilds = t[2, t[1]]
end
trees[myid].childs = mychilds
# 再帰的にdepthとparentを更新
rec(myid, mychilds, trees)
end
# root、internal node、leaf
trees.each do |t|
if t[1].parent == -1
t[1].tree_type = "root"
elsif t[1].childs.size.zero?
t[1].tree_type = "leaf"
else
t[1].tree_type = "internal node"
end
end
# 出力
n.times do |i|
puts "node #{trees[i].id}: parent = #{trees[i].parent}, depth = #{trees[i].depth}, #{trees[i].tree_type}, [#{trees[i].childs.map(&:to_s).join(', ')}]"
end
|
[
"expression.operation.unary.add",
"control_flow.branch.if.condition.change"
] | 122,459
| 122,460
|
u677096240
|
ruby
|
p02279
|
# ALDS1_7_A: Rooted Trees
class Node
attr_accessor :id, :parent, :left_child, :r_sib
def initialize()
@id = -1
end
def depth
@parent.nil? ? 0 : 1 + @parent.depth
end
def parent_id
@parent.nil? ? -1 : @parent.id
end
def child_ids
child_ids = []
child = @left_child
until child.nil?
child_ids << child.id
child = child.right_sib
end
child_ids
end
def type
return 'root' if parent.nil?
return 'leaf' if child_ids.empty?
'internal node'
end
end
n_nodes = gets.to_i
tree = Array.new(n_nodes).map { Node.new }
n_nodes.times do
id, n_child_ids, *child_ids = gets.split.map &:to_i
tree[id].id = id
next if child_ids.empty?
leftmost = child_ids[0]
tree[id].left_child = tree[leftmost]
child_ids.each_with_index do |child_id, i|
r_sib_id = child_ids[i + 1]
tree[child_id].r_sib = tree[r_sib_id] unless r_sib_id.nil?
tree[child_id].parent = tree[id]
end
end
tree.each do |n|
puts "node #{n.id}: parent = #{n.parent_id}, " <<
"depth = #{n.depth}, #{n.type}, #{n.child_ids}"
end
|
# ALDS1_7_A: Rooted Trees
class Node
attr_accessor :id, :parent, :left_child, :r_sib
def initialize()
@id = -1
end
def depth
@parent.nil? ? 0 : 1 + @parent.depth
end
def parent_id
@parent.nil? ? -1 : @parent.id
end
def child_ids
child_ids = []
child = @left_child
until child.nil?
child_ids << child.id
child = child.r_sib
end
child_ids
end
def type
return 'root' if parent.nil?
return 'leaf' if child_ids.empty?
'internal node'
end
end
n_nodes = gets.to_i
tree = Array.new(n_nodes).map { Node.new }
n_nodes.times do
id, n_child_ids, *child_ids = gets.split.map &:to_i
tree[id].id = id
next if child_ids.empty?
leftmost = child_ids[0]
tree[id].left_child = tree[leftmost]
child_ids.each_with_index do |child_id, i|
r_sib_id = child_ids[i + 1]
tree[child_id].r_sib = tree[r_sib_id] unless r_sib_id.nil?
tree[child_id].parent = tree[id]
end
end
tree.each do |n|
puts "node #{n.id}: parent = #{n.parent_id}, " <<
"depth = #{n.depth}, #{n.type}, #{n.child_ids}"
end
|
[
"assignment.value.change",
"identifier.change"
] | 122,461
| 122,462
|
u559743044
|
ruby
|
p02279
|
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
Node = Struct.new(:parent, :left, :right)
nodes = Array.new(N) { Node.new }
def get_depth(id, nodes)
d = 0
while ! nodes[id].parent.nil? do
id = nodes[id].parent
d += 1
end
d
end
def get_children(id, nodes)
children = []
c = nodes[id].left
while not c.nil?
children << c
c = nodes[c].right
end
children
end
for i in 1...(array.size)
carray = array[i].split(" ")
id = carray[0].to_i
k = carray[1].to_i
c = carray.slice(2, carray.length+1).map(&:to_i)
# set parents for each children
c.each do |child|
nodes[child].parent = id
end
# set left node for this node
nodes[id].left = c.first
# set left/right nodes
c.inject do |l, r|
nodes[l].right = r
end
end
nodes.each_with_index do |node, index|
children = get_children(index, nodes)
type = if children.empty? and node.parent.nil?
"root"
elsif children.empty?
"leaf"
else
"internal node"
end
puts "node #{index}: parent = #{node.parent.nil? ? -1 : node.parent}, depth = #{get_depth(index, nodes)}, #{type}, #{children.to_s}"
end
|
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
Node = Struct.new(:parent, :left, :right)
nodes = Array.new(N) { Node.new }
def get_depth(id, nodes)
d = 0
while ! nodes[id].parent.nil? do
id = nodes[id].parent
d += 1
end
d
end
def get_children(id, nodes)
children = []
c = nodes[id].left
while not c.nil?
children << c
c = nodes[c].right
end
children
end
for i in 1...(array.size)
carray = array[i].split(" ")
id = carray[0].to_i
k = carray[1].to_i
c = carray.slice(2, carray.length+1).map(&:to_i)
# set parents for each children
c.each do |child|
nodes[child].parent = id
end
# set left node for this node
nodes[id].left = c.first
# set left/right nodes
c.inject do |l, r|
nodes[l].right = r
end
end
nodes.each_with_index do |node, index|
children = get_children(index, nodes)
type = if node.parent.nil?
"root"
elsif children.empty?
"leaf"
else
"internal node"
end
puts "node #{index}: parent = #{node.parent.nil? ? -1 : node.parent}, depth = #{get_depth(index, nodes)}, #{type}, #{children.to_s}"
end
|
[
"expression.operation.binary.remove"
] | 122,467
| 122,468
|
u397596432
|
ruby
|
p02279
|
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
Node = Struct.new(:parent, :left, :right)
nodes = Array.new(N) { Node.new }
def get_depth(id, nodes)
d = 0
while ! nodes[id].parent.nil? do
id = nodes[id].parent
d += 1
end
d
end
def get_children(id, nodes)
children = []
c = nodes[id].left
while not c.nil?
children << c
c = nodes[c].right
end
children
end
for i in 1...(array.size)
carray = array[i].split(" ")
id = carray[0].to_i
k = carray[1].to_i
c = carray.slice(2, carray.length+1).map(&:to_i)
# set parents for each children
c.each do |child|
nodes[child].parent = id
end
# set left node for this node
nodes[id].left = c.first
# set left/right nodes
c.inject do |l, r|
nodes[l].right = r
end
end
nodes.each_with_index do |node, index|
children = get_children(index, nodes).sort
type = if node.parent.nil?
"root"
elsif children.empty?
"leaf"
else
"internal node"
end
puts "node #{index}: parent = #{node.parent.nil? ? -1 : node.parent}, depth = #{get_depth(index, nodes)}, #{type}, #{children.to_s}"
end
|
lines = $stdin.read
array = lines.split("\n")
N = array[0].to_i
Node = Struct.new(:parent, :left, :right)
nodes = Array.new(N) { Node.new }
def get_depth(id, nodes)
d = 0
while ! nodes[id].parent.nil? do
id = nodes[id].parent
d += 1
end
d
end
def get_children(id, nodes)
children = []
c = nodes[id].left
while not c.nil?
children << c
c = nodes[c].right
end
children
end
for i in 1...(array.size)
carray = array[i].split(" ")
id = carray[0].to_i
k = carray[1].to_i
c = carray.slice(2, carray.length+1).map(&:to_i)
# set parents for each children
c.each do |child|
nodes[child].parent = id
end
# set left node for this node
nodes[id].left = c.first
# set left/right nodes
c.inject do |l, r|
nodes[l].right = r
end
end
nodes.each_with_index do |node, index|
children = get_children(index, nodes)
type = if node.parent.nil?
"root"
elsif children.empty?
"leaf"
else
"internal node"
end
puts "node #{index}: parent = #{node.parent.nil? ? -1 : node.parent}, depth = #{get_depth(index, nodes)}, #{type}, #{children.to_s}"
end
|
[
"call.remove"
] | 122,469
| 122,468
|
u397596432
|
ruby
|
p02280
|
q=Array.new n=gets.to_i,M=-1
s=*q
g=$<.map{|l|i,*c=l.split.map &:to_i
c.reject!{|v|v<0}
c.map{|j|q[j]=i}
c[1]&&(a,b=c
s[a],s[b]=b,a)
[i,c]}.sort
d=->f,i,x{g[i][2]=x
g[i][3]=(g[i][1].map{|j|f[f,j,x+1]}.max||M)+1}
d[d,q.index(M),0]
g.map{|v|i,c,d,h=v
[i,p=q[i],s[i],c.size,d,h,p<0?:root:c[0]?"internal node": :leaf]}.map{|v|puts ["node %d: parent",:sibling,:degree,:depth,:height,"%s"]*" = %d, "%v}
|
q=Array.new n=gets.to_i,M=-1
s=*q
g=$<.map{|l|i,*c=l.split.map &:to_i
!i&&next
c.reject!{|v|v<0}
c.map{|j|q[j]=i}
c[1]&&(a,b=c
s[a],s[b]=b,a)
[i,c]}.compact.sort
d=->f,i,x{g[i][2]=x
g[i][3]=(g[i][1].map{|j|f[f,j,x+1]}.max||M)+1}
d[d,q.index(M),0]
g.map{|v|i,c,d,h=v
[i,p=q[i],s[i],c.size,d,h,p<0?:root:c[0]?"internal node": :leaf]}.map{|v|puts ["node %d: parent",:sibling,:degree,:depth,:height,"%s"]*" = %d, "%v}
|
[
"call.add"
] | 122,806
| 122,807
|
u890794282
|
ruby
|
p02280
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.left != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == -1
return i
end
}
end
#rt = findroot
rt=0
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.right != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == nil
return i
end
}
end
rt = findroot
#printf("root=%d\n",rt)
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"expression.operation.unary.remove",
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove"
] | 122,812
| 122,813
|
u708993917
|
ruby
|
p02280
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.left != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == -1
return i
end
}
end
#rt = findroot
rt=0
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.right != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == nil
return i
end
}
end
rt = findroot
#printf("root=%d\n",rt)
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"expression.operation.unary.remove",
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove"
] | 122,814
| 122,813
|
u708993917
|
ruby
|
p02280
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.left != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == nil
return i
end
}
end
rt = findroot
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
#binary_tree
class Node
attr_accessor :myname,:parent,:left,:right,:depth,:height
def initialize(n)
@myname = n
@parent = nil
@left = nil
@right = nil
@depth = 0
end
def add_left(child)
self.left = child
child.parent = self
end
def add_right(child)
self.right = child
child.parent = self
end
def set_depth(d)
self.depth = d
if(self.left != nil)
self.left.set_depth(d+1)
end
if(self.right != nil)
self.right.set_depth(d+1)
end
end
def set_height
if(self.left != nil)
lh=self.left.set_height
else
lh=0
end
if(self.right != nil)
rh=self.right.set_height
else
rh=0
end
if lh > rh
self.height = lh + 1
else
self.height = rh + 1
end
end
def sibling
p = self.parent
if p == nil
nil
elsif self == p.left
p.right
else
p.left
end
end
def degree
deg=0
if self.left != nil
deg += 1
end
if self.right != nil
deg += 1
end
deg
end
def shubetu
if self.parent == nil
"root"
elsif self.height == 1
"leaf"
else
"internal node"
end
end
def describe
printf("node %d:",self.myname)
if self.parent == nil
printf(" parent = -1,")
else
printf(" parent = %d,",self.parent.myname)
end
if self.sibling == nil
printf(" sibling = -1,")
else
printf(" sibling = %d,",self.sibling.myname)
end
printf(" degree = %d,",self.degree)
printf(" depth = %d,",self.depth)
printf(" height = %d,",self.height-1)
printf(" %s\n",self.shubetu)
end
end
$n = STDIN.gets.split[0].to_i
$tree=Array.new($n+1){|i| Node.new(i)}
0.upto($n-1){|i|
s = STDIN.gets.split
id= s[0].to_i
l = s[1].to_i
r = s[2].to_i
# printf("%d %d %d:\n",id,l,r)
if(l != -1)
$tree[id].add_left($tree[l])
end
if(r != -1)
$tree[id].add_right($tree[r])
end
}
def findroot
0.upto($n-1){|i|
if $tree[i].parent == nil
return i
end
}
end
rt = findroot
#printf("root=%d\n",rt)
$tree[rt].set_depth(0)
$tree[rt].set_height
0.upto($n-1){|i|
$tree[i].describe
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 122,815
| 122,813
|
u708993917
|
ruby
|
p02280
|
$arr=Array.new()
class BinaryTree
attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children
def initialize(id,children,degree)
@id=id
@parent=-1
@sibling=-1
@degree=degree
@height=0
@children=children
@type=(children==[-1,-1] ? 'leaf' :'internal node')
end
def print
puts "node #{id}: parent = #{parent}, sibling = #{sibling},degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
end
def setDepth
children.each do |c|
unless parent == -1
$arr[c].depth=depth+1
$arr[c].depth
end
end
end
def setHeight
unless parent==-1
$arr[parent].height=height+1 if $arr[parent].height<height+1
$arr[parent].setHeight
end
end
end
n=gets.to_i
n.times do
id,*children=gets.split.map(&:to_i)
degree=2
children.each do |e|
degree-=1 if e==-1
end
$arr << BinaryTree.new(id,children,degree)
end
$arr.sort_by! do |e| e.id end
$arr.each do |ele|
ele.children.each do |e|
unless e==-1
$arr[e].parent=ele.id
$arr[e].sibling=(e==ele.children[0] ? ele.children[1] : ele.children[0])
end
end
end
$arr.each do |e|
if e.parent==-1
e.type='root'
e.depth=0
e.setDepth
end
e.setHeight if e.type=='leaf'
end
$arr.each do |e|
e.print
end
|
$arr=Array.new()
class BinaryTree
attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children
def initialize(id,children,degree)
@id=id
@parent=-1
@sibling=-1
@degree=degree
@height=0
@children=children
@type=(children==[-1,-1] ? 'leaf' :'internal node')
end
def print
puts "node #{id}: parent = #{parent}, sibling = #{sibling}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
end
def setDepth
children.each do |c|
unless c==-1
$arr[c].depth = depth + 1
$arr[c].setDepth
end
end
end
def setHeight
unless parent==-1
$arr[parent].height=height+1 if $arr[parent].height<height+1
$arr[parent].setHeight
end
end
end
n=gets.to_i
n.times do
id,*children=gets.split.map(&:to_i)
degree=2
children.each do |e|
degree-=1 if e==-1
end
$arr << BinaryTree.new(id,children,degree)
end
$arr.sort_by! do |e| e.id end
$arr.each do |ele|
ele.children.each do |e|
unless e==-1
$arr[e].parent=ele.id
$arr[e].sibling=(e==ele.children[0] ? ele.children[1] : ele.children[0])
end
end
end
$arr.each do |e|
if e.parent==-1
e.type='root'
e.depth=0
e.setDepth
end
e.setHeight if e.type=='leaf'
end
$arr.each do |e|
e.print
end
|
[
"literal.string.change",
"call.arguments.change",
"identifier.change",
"expression.operation.binary.change"
] | 122,816
| 122,817
|
u083853290
|
ruby
|
p02280
|
$arr=Array.new()
class BinaryTree
attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children
def initialize(id,children,degree)
@id=id
@parent=-1
@sibling=-1
@degree=degree
@height=0
@children=children
@type=(children==[-1,-1] ? 'leaf' :'internal node')
end
def print
puts "node #{id}: parent = #{parent}, sibling = #{sibling},degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
end
def setDepth
children.each do |c|
unless c==-1
$arr[c].depth = depth + 1
$arr[c].setDepth
end
end
end
def setHeight
unless parent==-1
$arr[parent].height=height+1 if $arr[parent].height<height+1
$arr[parent].setHeight
end
end
end
n=gets.to_i
n.times do
id,*children=gets.split.map(&:to_i)
degree=2
children.each do |e|
degree-=1 if e==-1
end
$arr << BinaryTree.new(id,children,degree)
end
$arr.sort_by! do |e| e.id end
$arr.each do |ele|
ele.children.each do |e|
unless e==-1
$arr[e].parent=ele.id
$arr[e].sibling=(e==ele.children[0] ? ele.children[1] : ele.children[0])
end
end
end
$arr.each do |e|
if e.parent==-1
e.type='root'
e.depth=0
e.setDepth
end
e.setHeight if e.type=='leaf'
end
$arr.each do |e|
e.print
end
|
$arr=Array.new()
class BinaryTree
attr_accessor :id,:parent,:sibling,:degree,:depth,:height,:type,:children
def initialize(id,children,degree)
@id=id
@parent=-1
@sibling=-1
@degree=degree
@height=0
@children=children
@type=(children==[-1,-1] ? 'leaf' :'internal node')
end
def print
puts "node #{id}: parent = #{parent}, sibling = #{sibling}, degree = #{degree}, depth = #{depth}, height = #{height}, #{type}"
end
def setDepth
children.each do |c|
unless c==-1
$arr[c].depth = depth + 1
$arr[c].setDepth
end
end
end
def setHeight
unless parent==-1
$arr[parent].height=height+1 if $arr[parent].height<height+1
$arr[parent].setHeight
end
end
end
n=gets.to_i
n.times do
id,*children=gets.split.map(&:to_i)
degree=2
children.each do |e|
degree-=1 if e==-1
end
$arr << BinaryTree.new(id,children,degree)
end
$arr.sort_by! do |e| e.id end
$arr.each do |ele|
ele.children.each do |e|
unless e==-1
$arr[e].parent=ele.id
$arr[e].sibling=(e==ele.children[0] ? ele.children[1] : ele.children[0])
end
end
end
$arr.each do |e|
if e.parent==-1
e.type='root'
e.depth=0
e.setDepth
end
e.setHeight if e.type=='leaf'
end
$arr.each do |e|
e.print
end
|
[
"literal.string.change",
"call.arguments.change"
] | 122,818
| 122,817
|
u083853290
|
ruby
|
p02277
|
def part(a, q, r)
x = a[r][1]
i = q - 1
for j in 0...r - q
if a[q + j][1] <= x
i += 1
a[i], a[q + j] = a[q + j], a[i]
end
end
a[i + 1], a[r] = a[r], a[i + 1]
return i + 1
end
def qsort(a, q = nil, r = nil)
q, r = 0, a.length - 1 if !q
if q < r
x = part(a, q, r)
qsort(a, q, x - 1)
qsort(a, x + 1, r)
end
end
cards = []
gets.to_i.times do
cards << gets.split(" ")
cards.last[1] = cards.last[1].to_i
end
cards2 = cards.dup
qsort(cards)
i = 0
cards2.sort_by{|item|
i += 1
[item[1], i]
}
bool = true
cards.each_with_index{|item,idx|
bool &&= item == cards2[idx]
}
if bool
puts "Stable"
else
puts "Not stable"
end
cards.each{|item|puts item.join(" ")}
|
def part(a, q, r)
x = a[r][1]
i = q - 1
for j in 0...r - q
if a[q + j][1] <= x
i += 1
a[i], a[q + j] = a[q + j], a[i]
end
end
a[i + 1], a[r] = a[r], a[i + 1]
return i + 1
end
def qsort(a, q = nil, r = nil)
q, r = 0, a.length - 1 if !q
if q < r
x = part(a, q, r)
qsort(a, q, x - 1)
qsort(a, x + 1, r)
end
end
cards = []
gets.to_i.times do
cards << gets.split(" ")
cards.last[1] = cards.last[1].to_i
end
#cards = [["H", 3], ["S", 3], ["D", 3], ["C", 3], ["H", 1], ["S", 1], ["D", 1], ["H", 2], ["C", 1], ["S", 2], ["D", 2], ["C", 2]]
cards2 = cards.dup
qsort(cards)
i = 0
cards2.sort_by!{|item|
i += 1
[item[1], i]
}
#p cards2
bool = true
cards.each_with_index{|item,idx|
bool &&= item == cards2[idx]
}
if bool
puts "Stable"
else
puts "Not stable"
end
cards.each{|item|puts item.join(" ")}
|
[
"call.suffix.change"
] | 122,837
| 122,838
|
u514597327
|
ruby
|
p02277
|
def q a,l,r
l<r&&(
i=0
(a.size-1).times{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
def q a,l,r
l<r&&(
i=l
(l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
[
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"expression.operation.binary.change",
"identifier.change"
] | 122,839
| 122,840
|
u198069342
|
ruby
|
p02277
|
def q a,l,r
l<r&&(
i=0
(l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
def q a,l,r
l<r&&(
i=l
(l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
[
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"expression.operation.binary.change"
] | 122,841
| 122,840
|
u198069342
|
ruby
|
p02277
|
def q a,l,r
p [l,r]
l<r&&(
i=l
(l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
def q a,l,r
l<r&&(
i=l
(l..r-1).map{|j|a[j][2,20].to_i<=a[r][2,20].to_i&&(a[i],a[j]=a[j],a[i];i+=1)}
a[i],a[r]=a[r],a[i]
q a,l,i-1
q a,i+1,r
)
end
gets
a=$<.to_a
b=a.dup
q b,n=0,b.size-1
puts b==a.sort_by{|i|[i[2,20].to_i,n+=1]}?:Stable:"Not stable",b
|
[
"call.remove"
] | 122,842
| 122,840
|
u198069342
|
ruby
|
p02277
|
def partition(a, p, r)
unused, x = a[r].split(' ')
i = p - 1
p.upto(r-1) do |j|
unused, aj = a[j].split(' ')
if aj.to_i <= x.to_i
i = i + 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r], a[i+1]
return i + 1
end
def quickSort(a, p, r)
if p < r
q = partition(a, p, r)
quickSort(a, p, q-1)
quickSort(a, q+1, r)
end
end
def checkStable(origin, sorted)
originOrder = {}
sortedOrder = {}
(origin.size - 1).times do |i|
alphabet, num = origin[i].split(' ')
originOrder[num.to_i] = originOrder[num.to_i] == nil ? alphabet.to_s : originOrder[num.to_i] + alphabet.to_s
alphabet, num = sorted[i].split(' ')
sortedOrder[num.to_i] = sortedOrder[num.to_i] == nil ? alphabet.to_s : sortedOrder[num.to_i] + alphabet.to_s
end
return originOrder == sortedOrder ? 'Stable' : 'Not stable'
end
a = []
n = gets.to_i
n.times do
a.push(gets.to_s)
end
origin = Marshal.load(Marshal.dump(a))
quickSort(a, 0, a.size-1)
puts checkStable(origin, a)
puts a
|
def partition(a, p, r)
unused, x = a[r].split(' ')
i = p - 1
p.upto(r-1) do |j|
unused, aj = a[j].split(' ')
if aj.to_i <= x.to_i
i = i + 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r], a[i+1]
return i + 1
end
def quickSort(a, p, r)
if p < r
q = partition(a, p, r)
quickSort(a, p, q-1)
quickSort(a, q+1, r)
end
end
def checkStable(origin, sorted)
originOrder = {}
sortedOrder = {}
(origin.size).times do |i|
alphabet, num = origin[i].split(' ')
originOrder[num.to_i] = originOrder[num.to_i] == nil ? alphabet.to_s : originOrder[num.to_i] + alphabet.to_s
alphabet, num = sorted[i].split(' ')
sortedOrder[num.to_i] = sortedOrder[num.to_i] == nil ? alphabet.to_s : sortedOrder[num.to_i] + alphabet.to_s
end
return originOrder == sortedOrder ? 'Stable' : 'Not stable'
end
a = []
n = gets.to_i
n.times do
a.push(gets.to_s)
end
origin = Marshal.load(Marshal.dump(a))
quickSort(a, 0, a.size-1)
puts checkStable(origin, a)
puts a
|
[
"expression.operation.binary.remove"
] | 122,845
| 122,846
|
u878851603
|
ruby
|
p02277
|
def partition(a, p ,r)
x = a[r][1]
i = p-1
(p...r).each do |j|
if a[j][1] <= x
i += 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r], a[i+1]
return i+1
end
def quick_sort(a, p, r)
if p < r
q = partition(a, p, r)
quick_sort(a, p, q-1)
quick_sort(a, q+1, r)
end
end
n = gets.to_i
a = Array.new(n){ Array.new(2) }
n.times do |i|
a[i] = gets.split
a[i][1] = a[i][1].to_i
end
arr = a.clone
quick_sort(a, 0, n-1)
i = 0
arr.sort_by! do |item|
i += 1
[item[1], i]
end
bool = true
(0...n).each do |i|
if a[i][0] != arr[i][0] || a[i][1] != arr[i][1]
bool = false
break
end
end
puts "Stable" if bool
puts "Not Stable" unless bool
a.each do |ele|
puts ele.join(" ")
end
|
def partition(a, p ,r)
x = a[r][1]
i = p-1
(p...r).each do |j|
if a[j][1] <= x
i += 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r], a[i+1]
return i+1
end
def quick_sort(a, p, r)
if p < r
q = partition(a, p, r)
quick_sort(a, p, q-1)
quick_sort(a, q+1, r)
end
end
n = gets.to_i
a = Array.new(n){ Array.new(2) }
n.times do |i|
a[i] = gets.split
a[i][1] = a[i][1].to_i
end
arr = a.clone
quick_sort(a, 0, n-1)
i = 0
arr.sort_by! do |item|
i += 1
[item[1], i]
end
bool = true
(0...n).each do |i|
if a[i][0] != arr[i][0] || a[i][1] != arr[i][1]
bool = false
break
end
end
puts "Stable" if bool
puts "Not stable" unless bool
a.each do |ele|
puts ele.join(" ")
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 122,847
| 122,848
|
u920530014
|
ruby
|
p02277
|
def solve(n, cards)
a = []
b = []
p cards
for j in 0..(n-1)
m = cards[j][0]
i = cards[j][1].to_i
a.push([m, i])
b.push([m, i])
end
qsort(a, 0, n-1)
stable = true
(0..n-2).each do |i|
if (a[i][1] == a[i+1][1])
if b.index(a[i]) > b.index(a[i+1])
stable = false
break
end
end
end
if stable
puts("Stable")
else
puts("Not stable")
end
a.each do |x|
puts x.join(" ")
end
end
def qsort(a, p, r)
if p < r
q = partion(a, p, r)
qsort(a, p, q-1)
qsort(a, q+1, r)
end
end
def partion(a, p, r)
x = a[r][1]
i = p - 1
(p...r).each do |j|
if a[j][1] <= x
i += 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r] , a[i+1]
return i+1
end
n = gets.chomp.to_i
cards = []
n.times do
card = gets.chomp.split
cards.push(card)
end
solve(n, cards)
|
def solve(n, cards)
a = []
b = []
for j in 0..(n-1)
m = cards[j][0]
i = cards[j][1].to_i
a.push([m, i])
b.push([m, i])
end
qsort(a, 0, n-1)
stable = true
(0..n-2).each do |i|
if (a[i][1] == a[i+1][1])
if b.index(a[i]) > b.index(a[i+1])
stable = false
break
end
end
end
if stable
puts("Stable")
else
puts("Not stable")
end
a.each do |x|
puts x.join(" ")
end
end
def qsort(a, p, r)
if p < r
q = partion(a, p, r)
qsort(a, p, q-1)
qsort(a, q+1, r)
end
end
def partion(a, p, r)
x = a[r][1]
i = p - 1
(p...r).each do |j|
if a[j][1] <= x
i += 1
a[i], a[j] = a[j], a[i]
end
end
a[i+1], a[r] = a[r] , a[i+1]
return i+1
end
n = gets.chomp.to_i
cards = []
n.times do
card = gets.chomp.split
cards.push(card)
end
solve(n, cards)
|
[
"call.remove"
] | 122,851
| 122,852
|
u723368439
|
ruby
|
p02277
|
class Card
def initialize(mark, number)
@mark = mark
@number = number.to_i
end
def to_s
"#{mark} #{number}"
end
attr_accessor :number, :mark
end
def partition(array, p, r)
x = array[r].number
i = p - 1
p.upto(r - 1) do |index|
if array[index].number <= x
i += 1
array[i], array[index] = array[index], array[i]
end
end
array[r], array[i + 1] = array[i + 1], array[r]
i + 1
end
def quick_sort(array, p, r)
if p < r
q = partition array, p, r
quick_sort array, p, q - 1
quick_sort array, q + 1, r
end
array
end
def merge(left_array, right_array)
return_array = []
left_index, right_index = 0, 0
left_array << Card.new('', 10**9)
right_array << Card.new('', 10**9)
0.upto(left_array.length + right_array.length - 3) do
if left_array[left_index].number < right_array[right_index].number
return_array << left_array[left_index]
left_index += 1
else
return_array << right_array[right_index]
right_index += 1
end
end
return_array
end
def merge_sort(target_array)
right = target_array.length
mid = target_array.length / 2
left_array = target_array[0...mid]
right_array = target_array[mid...right]
return target_array if target_array.length == 1
merge(merge_sort(left_array), merge_sort(right_array))
end
def stable?(merge, sorted)
merge.each_with_index do |element, index|
return false if element.mark != sorted[index].mark
end
true
end
n = gets.to_i
input_array = []
n.times do
input = gets.split(' ')
input_array << Card.new(input[0], input[1])
end
input_array2 = Marshal.load(Marshal.dump(input_array))
merge = merge_sort input_array
quick = quick_sort input_array2, 0, n - 1
if stable? merge, quick
puts 'Stable'
else
puts 'Not stable'
end
puts quick.map(&:to_s)
|
class Card
def initialize(mark, number)
@mark = mark
@number = number.to_i
end
def to_s
"#{mark} #{number}"
end
attr_accessor :number, :mark
end
def partition(array, p, r)
x = array[r].number
i = p - 1
p.upto(r - 1) do |index|
if array[index].number <= x
i += 1
array[i], array[index] = array[index], array[i]
end
end
array[r], array[i + 1] = array[i + 1], array[r]
i + 1
end
def quick_sort(array, p, r)
if p < r
q = partition array, p, r
quick_sort array, p, q - 1
quick_sort array, q + 1, r
end
array
end
def merge(left_array, right_array)
return_array = []
left_index, right_index = 0, 0
left_array << Card.new('', 10**9)
right_array << Card.new('', 10**9)
0.upto(left_array.length + right_array.length - 3) do
if left_array[left_index].number <= right_array[right_index].number
return_array << left_array[left_index]
left_index += 1
else
return_array << right_array[right_index]
right_index += 1
end
end
return_array
end
def merge_sort(target_array)
right = target_array.length
mid = target_array.length / 2
left_array = target_array[0...mid]
right_array = target_array[mid...right]
return target_array if target_array.length == 1
merge(merge_sort(left_array), merge_sort(right_array))
end
def stable?(merge, sorted)
merge.each_with_index do |element, index|
return false if element.mark != sorted[index].mark
end
true
end
n = gets.to_i
input_array = []
n.times do
input = gets.split(' ')
input_array << Card.new(input[0], input[1])
end
input_array2 = Marshal.load(Marshal.dump(input_array))
merge = merge_sort input_array
quick = quick_sort input_array2, 0, n - 1
if stable? merge, quick
puts 'Stable'
else
puts 'Not stable'
end
puts quick.map(&:to_s)
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 122,853
| 122,854
|
u731989230
|
ruby
|
p02281
|
class Node
attr_accessor :parent, :left, :right
def initialize(p, l, r)
@parent = p
@left = l
@right = r
end
end
def make_tree n
tree = {}
[*0...n].each do |i|
tree[i] = Node.new(-1, nil ,nil)
end
n.times do
k, l, r = gets.chomp.split.map(&:to_i)
tree[k].left = l
tree[k].right = r
tree[l].parent = k if tree[l] != nil
tree[r].parent = k if tree[r] != nil
end
tree
end
def preorder(i, tree)
if i != -1
print " #{i}"
preorder(tree[i].left, tree)
preorder(tree[i].right, tree)
end
end
def inorder(i, tree)
if i != -1
inorder(tree[i].left, tree)
print " #{i}"
inorder(tree[i].right, tree)
end
end
def postorder(i, tree)
if i != -1
postorder(tree[i].left, tree)
postorder(tree[i].right, tree)
print " #{i}"
end
end
n = gets.chomp.to_i
tree = make_tree(n)
root = -1
tree.each do |(k, v)|
p v.parent
root = k if v.parent == -1
end
puts "Preorder"; preorder(root, tree); puts
puts "Inorder"; inorder(root, tree); puts
puts "Postorder"; postorder(root, tree); puts
|
class Node
attr_accessor :parent, :left, :right
def initialize(p, l, r)
@parent = p
@left = l
@right = r
end
end
def make_tree n
tree = {}
[*0...n].each do |i|
tree[i] = Node.new(-1, nil ,nil)
end
n.times do
k, l, r = gets.chomp.split.map(&:to_i)
tree[k].left = l
tree[k].right = r
tree[l].parent = k if tree[l] != nil
tree[r].parent = k if tree[r] != nil
end
tree
end
def preorder(i, tree)
if i != -1
print " #{i}"
preorder(tree[i].left, tree)
preorder(tree[i].right, tree)
end
end
def inorder(i, tree)
if i != -1
inorder(tree[i].left, tree)
print " #{i}"
inorder(tree[i].right, tree)
end
end
def postorder(i, tree)
if i != -1
postorder(tree[i].left, tree)
postorder(tree[i].right, tree)
print " #{i}"
end
end
n = gets.chomp.to_i
tree = make_tree(n)
root = -1
tree.each do |(k, v)|
root = k if v.parent == -1
end
puts "Preorder"; preorder(root, tree); puts
puts "Inorder"; inorder(root, tree); puts
puts "Postorder"; postorder(root, tree); puts
|
[
"call.remove"
] | 123,293
| 123,294
|
u573990433
|
ruby
|
p02284
|
class Tree
attr_accessor :id,:parent,:children
def initialize(id)
@id=id
@parent=-1
@children=[nil,nil]
end
def preorder
print " #{id}"
children[0].preorder if children[0]
children[1].preorder if children[1]
end
def inorder
children[0].inorder if children[0]
print " #{id}"
children[1].inorder if children[1]
end
end
def insert(id)
z=Tree.new(id)
y=nil
x=$root
while x
y=x
x= z.id < x.id ? x.children[0] : x.children[1]
end
unless y
$root=z
else
z.id < y.id ? y.children[0]=z : y.children[1]=z
end
end
def find(id)
x=$root
while x!=nil && id!=x.id
if id<x.id
x=x.children[0]
else
x=x.children[1]
end
end
return x
end
N=gets.to_i
N.times do
cmd,id=gets.split
case cmd
when "insert"
insert(id.to_i)
when "find"
if find(id.to_i)
puts "Yes"
else
puts "No"
end
else
$root.inorder
puts ""
$root.preorder
puts ""
end
end
|
class Tree
attr_accessor :id,:parent,:children
def initialize(id)
@id=id
@parent=-1
@children=[nil,nil]
end
def preorder
print " #{id}"
children[0].preorder if children[0]
children[1].preorder if children[1]
end
def inorder
children[0].inorder if children[0]
print " #{id}"
children[1].inorder if children[1]
end
end
def insert(id)
z=Tree.new(id)
y=nil
x=$root
while x
y=x
x= z.id < x.id ? x.children[0] : x.children[1]
end
unless y
$root=z
else
z.id < y.id ? y.children[0]=z : y.children[1]=z
end
end
def find(id)
x=$root
while x!=nil && id!=x.id
if id<x.id
x=x.children[0]
else
x=x.children[1]
end
end
return x
end
N=gets.to_i
N.times do
cmd,id=gets.split
case cmd
when "insert"
insert(id.to_i)
when "find"
if find(id.to_i)
puts "yes"
else
puts "no"
end
else
$root.inorder
puts ""
$root.preorder
puts ""
end
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 124,476
| 124,477
|
u083853290
|
ruby
|
p02285
|
CMD=0
VAL=1
class Node
attr_accessor :value,:left,:right,:parent
def initialize (value,parent)
@value = value
@parent = parent
@left = nil
@right = nil
end
def insert (value)
if value < @value
if @left.nil?
@left = Node.new(value,self)
else
@left.insert(value)
end
else
if @right.nil?
@right = Node.new(value,self)
else
@right.insert(value)
end
end
end
def find(value)
if value==@value
print "yes\n"
elsif value < @value
if @left.nil?
print "no\n"
else
@left.find(value)
end
else
if @right.nil?
print "no\n"
else
@right.find(value)
end
end
end
def delete(value)
# p "before:#{@value}"
if value == @value
if @left.nil? or @right.nil?
# p "removed"
update_tree
else
@value = get_new_value
# p "after:#{@value}"
end
elsif value < @value
@left.delete(value)
else
@right.delete(value)
end
end
def get_new_value
unless @left.nil?
return @left.get_new_value
else
update_tree
return @value
end
end
def update_tree
# p "value: #{@value}"
# p "@parent.value: #{@parent.value}"
if @left.nil? and @right.nil?
new_child = nil
elsif @left.nil?
new_child = @right
elsif @right.nil?
new_child = @left
else
p "oops"
end
new_child.parent = @parent unless new_child.nil?
if @value < @parent.value
@parent.left = new_child
# p "parent left: #{@parent.left}"
else
@parent.right = new_child
# p "parent right: #{@parent.right}"
end
end
def print_inorder
@left.print_inorder unless @left.nil?
print " #{value}"
@right.print_inorder unless @right.nil?
end
def print_preorder
print " #{value}"
@left.print_preorder unless @left.nil?
@right.print_preorder unless @right.nil?
end
end
num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }
root=nil
inputs.each do |input|
if input[CMD] == 'insert'
if root.nil?
root = Node.new(input[VAL].to_i,nil)
else
root.insert(input[VAL].to_i)
end
elsif input[CMD] == 'find'
root.find(input[VAL].to_i)
elsif input[CMD] == 'delete'
root.delete(input[VAL].to_i)
else
root.print_inorder unless root.nil?
print "\n"
root.print_preorder unless root.nil?
print "\n"
end
end
|
CMD=0
VAL=1
class Node
attr_accessor :value,:left,:right,:parent
def initialize (value,parent)
@value = value
@parent = parent
@left = nil
@right = nil
end
def insert (value)
if value < @value
if @left.nil?
@left = Node.new(value,self)
else
@left.insert(value)
end
else
if @right.nil?
@right = Node.new(value,self)
else
@right.insert(value)
end
end
end
def find(value)
if value==@value
print "yes\n"
elsif value < @value
if @left.nil?
print "no\n"
else
@left.find(value)
end
else
if @right.nil?
print "no\n"
else
@right.find(value)
end
end
end
def delete(value)
#p "before:#{@value}"
if value == @value
if @left.nil? or @right.nil?
#p "removed"
update_tree
else
@value = @right.get_new_value
#p "after:#{@value}"
end
elsif value < @value
@left.delete(value)
else
@right.delete(value)
end
end
def get_new_value
unless @left.nil?
return @left.get_new_value
else
update_tree
return @value
end
end
def update_tree
#p "value: #{@value}"
#p "@parent.value: #{@parent.value}"
if @left.nil? and @right.nil?
new_child = nil
elsif @left.nil?
new_child = @right
elsif @right.nil?
new_child = @left
else
p "oops"
end
new_child.parent = @parent unless new_child.nil?
if @value < @parent.value
@parent.left = new_child
#p "parent left: #{@parent.left}"
else
@parent.right = new_child
#p "parent right: #{@parent.right}"
end
end
def print_inorder
@left.print_inorder unless @left.nil?
print " #{value}"
@right.print_inorder unless @right.nil?
end
def print_preorder
print " #{value}"
@left.print_preorder unless @left.nil?
@right.print_preorder unless @right.nil?
end
end
num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }
root=nil
inputs.each do |input|
if input[CMD] == 'insert'
if root.nil?
root = Node.new(input[VAL].to_i,nil)
else
root.insert(input[VAL].to_i)
end
elsif input[CMD] == 'find'
root.find(input[VAL].to_i)
elsif input[CMD] == 'delete'
root.delete(input[VAL].to_i)
else
root.print_inorder unless root.nil?
print "\n"
root.print_preorder unless root.nil?
print "\n"
end
end
|
[
"call.add"
] | 124,863
| 124,864
|
u054278963
|
ruby
|
p02287
|
class Node
def initialize(i, key)
@index = i
@key = key
@parent_key = nil
@left_key = nil
@right_key = nil
end
def to_s
str = "node #{index}: key = #{key}, "
str += "parent_key = #{@parent_key.key}, " unless @parent_key.nil?
str += "left_key = #{@left_key.key}, " unless @left_key.nil?
str += "right_key = #{@right_key.key}, " unless @right_key.nil?
str
end
attr_accessor :index, :key
attr_writer :parent_key, :right_key, :left_key
end
h = gets.to_i
input = gets.split(' ').map(&:to_i)
heap = []
input.each_with_index do |value, index|
heap << Node.new(index + 1, value)
end
heap.each do |value|
value.parent_key = heap[value.index / 2 - 1] unless heap[value.index / 2 - 1].nil? || value.index == 1
value.right_key = heap[value.index * 2] unless heap[value.index * 2].nil?
value.left_key = heap[value.index * 2 - 1] unless heap[value.index * 2 - 1].nil?
end
puts heap.map(&:to_s)
|
class Node
def initialize(i, key)
@index = i
@key = key
@parent_key = nil
@left_key = nil
@right_key = nil
end
def to_s
str = "node #{index}: key = #{key}, "
str += "parent key = #{@parent_key.key}, " unless @parent_key.nil?
str += "left key = #{@left_key.key}, " unless @left_key.nil?
str += "right key = #{@right_key.key}, " unless @right_key.nil?
str
end
attr_accessor :index, :key
attr_writer :parent_key, :right_key, :left_key
end
h = gets.to_i
input = gets.split(' ').map(&:to_i)
heap = []
input.each_with_index do |value, index|
heap << Node.new(index + 1, value)
end
heap.each do |value|
value.parent_key = heap[value.index / 2 - 1] unless heap[value.index / 2 - 1].nil? || value.index == 1
value.right_key = heap[value.index * 2] unless heap[value.index * 2].nil?
value.left_key = heap[value.index * 2 - 1] unless heap[value.index * 2 - 1].nil?
end
puts heap.map(&:to_s)
|
[
"literal.string.change"
] | 125,414
| 125,415
|
u731989230
|
ruby
|
p02287
|
class Node
attr_accessor :id, :key, :parent, :left, :right
def initialize(id, key)
@id = id
@key = key
@parent = nil
@left = nil
@right = nil
end
def to_s
parent_s =
if @parent != nil
"parent key = #{@parent.key}, "
else
""
end
left_s =
if @left != nil
"left key = #{@left.key}, "
else
""
end
right_s =
if @right != nil
"right key = #{@right.key}, "
else
""
end
"node #{@id}: key = #{@key}, #{parent_s}#{left_s}#{right_s}"
end
end
def left_p(i)
2 * i
end
def right_p(i)
2 * i + 1
end
def parent_p(i)
i / 2
end
n = STDIN.gets.to_i
arr = STDIN.gets.split(' ')
tree = []
arr.each_with_index { |a, i|
id = i + 1
left_p = left_p(id)
right_p = right_p(id)
node = Node.new(id, a)
if arr.size > left_p
left = Node.new(left_p, arr[left_p - 1])
left.parent = node
node.left = left
end
if arr.size > right_p
right = Node.new(right_p, arr[right_p - 1])
right.parent = node
node.right = right
end
node.parent = tree[parent_p(i+1) - 1]
tree[i] = node
}
tree.each {|a|
puts a
}
|
class Node
attr_accessor :id, :key, :parent, :left, :right
def initialize(id, key)
@id = id
@key = key
@parent = nil
@left = nil
@right = nil
end
def to_s
parent_s =
if @parent != nil
"parent key = #{@parent.key}, "
else
""
end
left_s =
if @left != nil
"left key = #{@left.key}, "
else
""
end
right_s =
if @right != nil
"right key = #{@right.key}, "
else
""
end
"node #{@id}: key = #{@key}, #{parent_s}#{left_s}#{right_s}"
end
end
def left_p(i)
2 * i
end
def right_p(i)
2 * i + 1
end
def parent_p(i)
i / 2
end
n = STDIN.gets.to_i
arr = STDIN.gets.split(' ')
tree = []
arr.each_with_index { |a, i|
id = i + 1
left_p = left_p(id)
right_p = right_p(id)
node = Node.new(id, a)
if arr.size >= left_p
left = Node.new(left_p, arr[left_p - 1])
left.parent = node
node.left = left
end
if arr.size >= right_p
right = Node.new(right_p, arr[right_p - 1])
right.parent = node
node.right = right
end
node.parent = tree[parent_p(i+1) - 1]
tree[i] = node
}
tree.each {|a|
puts a
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 125,418
| 125,419
|
u382730661
|
ruby
|
p02287
|
def parent(i)
return i/2
end
def left(i)
return i*2
end
def right(i)
return i*2+1
end
n=gets.to_i
arr=gets.split.map(&:to_i)
arr.unshift(nil)
(1..n).each do |i|
print "node #{i}, key = #{arr[i]}, "
if parent(i)>=1
print "parent key = #{arr[parent(i)]}, "
end
if left(i)<=n
print "left key = #{arr[left(i)]}, "
end
if right(i)<=n
print "right key = #{arr[right(i)]}, "
end
puts ""
end
|
def parent(i)
return i/2
end
def left(i)
return i*2
end
def right(i)
return i*2+1
end
n=gets.to_i
arr=gets.split.map(&:to_i)
arr.unshift(nil)
(1..n).each do |i|
print "node #{i}: key = #{arr[i]}, "
if parent(i)>=1
print "parent key = #{arr[parent(i)]}, "
end
if left(i)<=n
print "left key = #{arr[left(i)]}, "
end
if right(i)<=n
print "right key = #{arr[right(i)]}, "
end
puts ""
end
|
[
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 125,427
| 125,428
|
u083853290
|
ruby
|
p02287
|
n = gets.to_i
heep = gets.split.map(&:to_i)
heep.each_with_index{|val, j|
i = j + 1
str = "node #{j}: key = #{val}, "
str << "parent key = #{heep[i/2-1]}, " if j > 0
str << "left key = #{heep[2*i-1]}, " if 2 * i - 1 < n
str << "right key = #{heep[2*i]}, " if 2 * i < n
puts str
}
|
n = gets.to_i
heep = gets.split.map(&:to_i)
heep.each_with_index{|val, j|
i = j + 1
str = "node #{i}: key = #{val}, "
str << "parent key = #{heep[i/2-1]}, " if j > 0
str << "left key = #{heep[2*i-1]}, " if 2 * i - 1 < n
str << "right key = #{heep[2*i]}, " if 2 * i < n
puts str
}
|
[
"literal.string.change",
"assignment.value.change"
] | 125,435
| 125,436
|
u960312159
|
ruby
|
p02283
|
CMD=0
VAL=1
class Node
attr_accessor :value,:left,:right
def initialize (value)
@value = value
@left = nil
@right = nil
end
def insert (value)
if value < @value
if @left.nil?
@left = Node.new(value)
else
@left.insert(value)
end
else
if @right.nil?
@right = Node.new(value)
else
@right.insert(value)
end
end
end
def print_inorder
@left.print_inorder unless @left.nil?
print "#{value} "
@right.print_inorder unless @right.nil?
end
def print_preorder
print "#{value} "
@left.print_inorder unless @left.nil?
@right.print_inorder unless @right.nil?
end
end
num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }
root=nil
inputs.each do |input|
if input[CMD] == 'insert'
if root.nil?
root = Node.new(input[VAL].to_i)
else
root.insert(input[VAL].to_i)
end
else
root.print_inorder unless root.nil?
print "\n"
root.print_preorder unless root.nil?
print "\n"
end
end
|
CMD=0
VAL=1
class Node
attr_accessor :value,:left,:right
def initialize (value)
@value = value
@left = nil
@right = nil
end
def insert (value)
if value < @value
if @left.nil?
@left = Node.new(value)
else
@left.insert(value)
end
else
if @right.nil?
@right = Node.new(value)
else
@right.insert(value)
end
end
end
def print_inorder
@left.print_inorder unless @left.nil?
print " #{value}"
@right.print_inorder unless @right.nil?
end
def print_preorder
print " #{value}"
@left.print_preorder unless @left.nil?
@right.print_preorder unless @right.nil?
end
end
num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }
root=nil
inputs.each do |input|
if input[CMD] == 'insert'
if root.nil?
root = Node.new(input[VAL].to_i)
else
root.insert(input[VAL].to_i)
end
else
root.print_inorder unless root.nil?
print "\n"
root.print_preorder unless root.nil?
print "\n"
end
end
|
[
"literal.string.change",
"call.arguments.change",
"identifier.change"
] | 125,920
| 125,921
|
u054278963
|
ruby
|
p02288
|
class Node
include Comparable
def initialize(id, key)
@id = id
@key = key
end
def <=>(other)
@key <=> other.key
end
DUMMY = Node.new(-1, -1)
attr_accessor :id, :key
end
def maxHeapify(array, i)
left = (i*2 < array.size) ? array[i*2] : Node::DUMMY
right = (i*2+1 < array.size) ? array[i*2+1] : Node::DUMMY
max = [array[i], left, right].sort_by{|x| x.key}.pop
max_key = max.key
if (left.key == max.key) then
left.key = array[i].key
array[i].key = max_key
maxHeapify(array, left.id)
elsif (right.key == max.key) then
right.key = array[i].key
array[i].key = max_key
maxHeapify(array, right.id)
end
end
def buildMaxHeap(array)
((array.size-1) / 2).downto(1) do |i|
maxHeapify(array, i)
end
end
# main
n = gets.chomp.to_i
input = gets.chomp.split.map(&:to_i)
array = [n]
input.each_with_index do |key, id|
id += 1
node = Node.new(id, key)
array << node
end
buildMaxHeap(array)
array.shift
puts " #{array.map{|x| x.key}.join(' ')}"
|
class Node
include Comparable
def initialize(id, key)
@id = id
@key = key
end
def <=>(other)
@key <=> other.key
end
DUMMY = Node.new(-1, -2_000_000_001)
attr_accessor :id, :key
end
def maxHeapify(array, i)
left = (i*2 < array.size) ? array[i*2] : Node::DUMMY
right = (i*2+1 < array.size) ? array[i*2+1] : Node::DUMMY
max = [array[i], left, right].sort_by{|x| x.key}.pop
max_key = max.key
if (left.key == max.key) then
left.key = array[i].key
array[i].key = max_key
maxHeapify(array, left.id)
elsif (right.key == max.key) then
right.key = array[i].key
array[i].key = max_key
maxHeapify(array, right.id)
end
end
def buildMaxHeap(array)
((array.size-1) / 2).downto(1) do |i|
maxHeapify(array, i)
end
end
# main
n = gets.chomp.to_i
input = gets.chomp.split.map(&:to_i)
array = [n]
input.each_with_index do |key, id|
id += 1
node = Node.new(id, key)
array << node
end
buildMaxHeap(array)
array.shift
puts " #{array.map{|x| x.key}.join(' ')}"
|
[
"literal.number.integer.change",
"assignment.value.change",
"call.arguments.change"
] | 126,371
| 126,372
|
u148091382
|
ruby
|
p02288
|
def maxHeapify(x)
l = 2*x
r = 2*x+1
if l <= $n && $heap[l] > $heap[x]
largest = l
else
largest = x
end
if r <= $n && $heap[r] > $heap[largest]
largest = r
end
if largest != x
$heap[x], $heap[largest] = $heap[largest], $heap[x]
maxHeapify(largest)
end
end
def buildMaxHeap
($n/2).downto(1){ |i| maxHeapify(i) }
end
$n = gets.to_i
$heap = gets.split.map(&:to_i)
$heap.unshit nil
buildMaxHeap
$heap.shift
$heap.each{ |i| print " ", i }
puts
|
def maxHeapify(x)
l = 2*x
r = 2*x+1
if l <= $n && $heap[l] > $heap[x]
largest = l
else
largest = x
end
if r <= $n && $heap[r] > $heap[largest]
largest = r
end
if largest != x
$heap[x], $heap[largest] = $heap[largest], $heap[x]
maxHeapify(largest)
end
end
def buildMaxHeap
($n/2).downto(1){ |i| maxHeapify(i) }
end
$n = gets.to_i
$heap = gets.split.map(&:to_i)
$heap.unshift nil
buildMaxHeap
$heap.shift
$heap.each{ |i| print " ", i }
puts
|
[
"identifier.change"
] | 126,376
| 126,377
|
u811434779
|
ruby
|
p02290
|
require 'matrix'
p1x, p1y, p2x, p2y = gets.split.map &:to_i
p1 = Vector[ p1x, p1y ]
p1p2 = Vector[ p2x - p1x, p2y - p1y ]
q = gets.to_i
q.times do
px, py = gets.split.map &:to_i
p1p = Vector[ px - p1x, py - p1y ]
p1t_norm = p1p.innter_product(p1p2) / p1p2.norm
t = p1 + p1p2 * ( p1t_norm / p1p2.norm )
puts "%.8f %.8f" % [ t[0], t[1] ]
end
|
require 'matrix'
p1x, p1y, p2x, p2y = gets.split.map &:to_i
p1 = Vector[ p1x, p1y ]
p1p2 = Vector[ p2x - p1x, p2y - p1y ]
q = gets.to_i
q.times do
px, py = gets.split.map &:to_i
p1p = Vector[ px - p1x, py - p1y ]
p1t_norm = p1p.inner_product(p1p2) / p1p2.norm
t = p1 + p1p2 * ( p1t_norm / p1p2.norm )
puts "%.8f %.8f" % [ t[0], t[1] ]
end
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change",
"io.output.change"
] | 127,736
| 127,737
|
u352522848
|
ruby
|
p02293
|
require 'matrix'
q = gets.to_i
x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
s1 = Vector[ x1 - x0, y1 - y0, 0 ]
s2 = Vector[ x3 - x2, y3 - y2, 0 ]
if s1.inner_product(s1) == 0
puts 1
elsif s1.cross_product(s2).norm == 0
puts 2
else
puts 0
end
|
require 'matrix'
q = gets.to_i
q.times do
x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
s1 = Vector[ x1 - x0, y1 - y0, 0 ]
s2 = Vector[ x3 - x2, y3 - y2, 0 ]
if s1.inner_product(s2) == 0
puts 1
elsif s1.cross_product(s2).norm == 0
puts 2
else
puts 0
end
end
|
[
"call.add",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 128,010
| 128,011
|
u352522848
|
ruby
|
p02293
|
require 'matrix'
q = gets.to_i
q.times do
x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
s1 = Vector[ x1 - x0, y1 - y0, 0 ]
s2 = Vector[ x3 - x2, y3 - y2, 0 ]
if s1.inner_product(s1) == 0
puts 1
elsif s1.cross_product(s2).norm == 0
puts 2
else
puts 0
end
end
|
require 'matrix'
q = gets.to_i
q.times do
x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
s1 = Vector[ x1 - x0, y1 - y0, 0 ]
s2 = Vector[ x3 - x2, y3 - y2, 0 ]
if s1.inner_product(s2) == 0
puts 1
elsif s1.cross_product(s2).norm == 0
puts 2
else
puts 0
end
end
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 128,012
| 128,011
|
u352522848
|
ruby
|
p02289
|
#!/usr/bin/ruby
def heappush(heap, item)
heap.push(item)
_siftdown(heap, 0, heap.size-1)
end
def heappop(heap)
lastelt = heap.pop
if !heap.empty?
returnitem = heap[0]
heap[0] = lastelt
_siftup(heap, 0)
else
returnitem = lastelt
end
returnitem
end
def heappushpop(heap, item)
if !heap.empty? && (heap[0]<=>item)<0
item, heap[0] = heap[0], item
_siftup(heap, 0)
end
item
end
def heapify(x)
n = x.size
(n/2-1).downto(0){|i|_siftup(x, i)}
end
def _siftdown(heap, startpos, pos)
newitem = heap[pos]
while pos > startpos
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if (newitem<=>parent)<0
heap[pos] = parent
pos = parentpos
else
break
end
end
heap[pos] = newitem
end
def _siftup(heap, pos)
endpos = heap.size
startpos = pos
newitem = heap[pos]
childpos = 2*pos + 1
while childpos < endpos
rightpos = childpos + 1
if rightpos < endpos && (heap[childpos]<=>heap[rightpos])>=0
childpos = rightpos
end
heap[pos] = heap[childpos]
pos = childpos
childpos = 2*pos + 1
end
heap[pos] = newitem
_siftdown(heap, startpos, pos)
end
### main ###
q=[]
loop{
a=gets.split
break if a[0]=='end'
if a[0]=='insert'
heappush(q,a[1].to_i)
else
p heappop(q)
end
}
|
#!/usr/bin/ruby
def heappush(heap, item)
heap.push(item)
_siftdown(heap, 0, heap.size-1)
end
def heappop(heap)
lastelt = heap.pop
if !heap.empty?
returnitem = heap[0]
heap[0] = lastelt
_siftup(heap, 0)
else
returnitem = lastelt
end
returnitem
end
def heappushpop(heap, item)
if !heap.empty? && (heap[0]<=>item)<0
item, heap[0] = heap[0], item
_siftup(heap, 0)
end
item
end
def heapify(x)
n = x.size
(n/2-1).downto(0){|i|_siftup(x, i)}
end
def _siftdown(heap, startpos, pos)
newitem = heap[pos]
while pos > startpos
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if (newitem<=>parent)<0
heap[pos] = parent
pos = parentpos
else
break
end
end
heap[pos] = newitem
end
def _siftup(heap, pos)
endpos = heap.size
startpos = pos
newitem = heap[pos]
childpos = 2*pos + 1
while childpos < endpos
rightpos = childpos + 1
if rightpos < endpos && (heap[childpos]<=>heap[rightpos])>=0
childpos = rightpos
end
heap[pos] = heap[childpos]
pos = childpos
childpos = 2*pos + 1
end
heap[pos] = newitem
_siftdown(heap, startpos, pos)
end
### main ###
q=[]
loop{
a=gets.split
break if a[0]=='end'
if a[0]=='insert'
heappush(q,-a[1].to_i)
else
p -heappop(q)
end
}
|
[
"expression.operation.unary.add",
"call.arguments.change"
] | 128,061
| 128,062
|
u300645821
|
ruby
|
p02289
|
#!/usr/bin/ruby
def heappush(heap, item)
heap.push(item)
_siftdown(heap, 0, heap.size-1)
end
def heappop(heap)
lastelt = heap.pop
if !heap.empty?
returnitem = heap[0]
heap[0] = lastelt
_siftup(heap, 0)
else
returnitem = lastelt
end
returnitem
end
def heappushpop(heap, item)
if !heap.empty? && (heap[0]<=>item)<0
item, heap[0] = heap[0], item
_siftup(heap, 0)
end
item
end
def heapify(x)
n = x.size
(n/2-1).downto(0){|i|_siftup(x, i)}
end
def _siftdown(heap, startpos, pos)
newitem = heap[pos]
while pos > startpos
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if (newitem<=>parent)<0
heap[pos] = parent
pos = parentpos
else
break
end
end
heap[pos] = newitem
end
def _siftup(heap, pos)
endpos = heap.size
startpos = pos
newitem = heap[pos]
childpos = 2*pos + 1
while childpos < endpos
rightpos = childpos + 1
if rightpos < endpos && (heap[childpos]<=>heap[rightpos])>=0
childpos = rightpos
end
heap[pos] = heap[childpos]
pos = childpos
childpos = 2*pos + 1
end
heap[pos] = newitem
_siftdown(heap, startpos, pos)
end
### main ###
q=[]
loop{
a=gets.split
break if a[0]=='end'
if a[0]=='insert'
heappush(q,-a[1].to_i)
else
p heappop(-q)
end
}
|
#!/usr/bin/ruby
def heappush(heap, item)
heap.push(item)
_siftdown(heap, 0, heap.size-1)
end
def heappop(heap)
lastelt = heap.pop
if !heap.empty?
returnitem = heap[0]
heap[0] = lastelt
_siftup(heap, 0)
else
returnitem = lastelt
end
returnitem
end
def heappushpop(heap, item)
if !heap.empty? && (heap[0]<=>item)<0
item, heap[0] = heap[0], item
_siftup(heap, 0)
end
item
end
def heapify(x)
n = x.size
(n/2-1).downto(0){|i|_siftup(x, i)}
end
def _siftdown(heap, startpos, pos)
newitem = heap[pos]
while pos > startpos
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if (newitem<=>parent)<0
heap[pos] = parent
pos = parentpos
else
break
end
end
heap[pos] = newitem
end
def _siftup(heap, pos)
endpos = heap.size
startpos = pos
newitem = heap[pos]
childpos = 2*pos + 1
while childpos < endpos
rightpos = childpos + 1
if rightpos < endpos && (heap[childpos]<=>heap[rightpos])>=0
childpos = rightpos
end
heap[pos] = heap[childpos]
pos = childpos
childpos = 2*pos + 1
end
heap[pos] = newitem
_siftdown(heap, startpos, pos)
end
### main ###
q=[]
loop{
a=gets.split
break if a[0]=='end'
if a[0]=='insert'
heappush(q,-a[1].to_i)
else
p -heappop(q)
end
}
|
[
"expression.operation.unary.add",
"call.arguments.change",
"expression.operation.unary.arithmetic.remove"
] | 128,063
| 128,062
|
u300645821
|
ruby
|
p02294
|
require 'matrix'
q = gets.to_i
def cross(p1, p2)
return p1[0] * p2[1] - p1[1] * p2[0]
end
q.times do
p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y = gets.split.map &:to_i
p0 = Vector[ p0x, p0y ]
p1 = Vector[ p1x, p1y ]
p2 = Vector[ p2x, p2y ]
p3 = Vector[ p3x, p3y ]
if cross(p1-p0, p2-p0) * cross(p1-p0, p3-p0) < 0 &&
cross(p3-p2, p0-p2) * cross(p3-p2, p1-p2) < 0
puts 1
elsif ( cross(p1-p0, p2-p0) == 0 && (p1-p0).inner_product(p2-p0) > 0 && (p2-p0).norm <= (p1-p0).norm ) ||
( cross(p1-p0, p3-p0) == 0 && (p1-p0).inner_product(p3-p0) > 0 && (p3-p0).norm <= (p1-p0).norm )
puts 1
elsif ( cross(p3-p2, p0-p2) == 0 && (p3-p2).inner_product(p0-p2) > 0 && (p0-p2).norm <= (p3-p2).norm ) ||
( cross(p3-p2, p1-p2) == 0 && (p3-p2).inner_product(p1-p2) > 0 && (p1-p2).norm <= (p3-p2).norm )
puts 1
else
puts 0
end
end
|
require 'matrix'
q = gets.to_i
def cross(p1, p2)
return p1[0] * p2[1] - p1[1] * p2[0]
end
q.times do
p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y = gets.split.map &:to_i
p0 = Vector[ p0x, p0y ]
p1 = Vector[ p1x, p1y ]
p2 = Vector[ p2x, p2y ]
p3 = Vector[ p3x, p3y ]
if cross(p1-p0, p2-p0) * cross(p1-p0, p3-p0) < 0 &&
cross(p3-p2, p0-p2) * cross(p3-p2, p1-p2) < 0
puts 1
elsif ( cross(p1-p0, p2-p0) == 0 && (p1-p0).inner_product(p2-p0) >= 0 && (p2-p0).norm <= (p1-p0).norm ) ||
( cross(p1-p0, p3-p0) == 0 && (p1-p0).inner_product(p3-p0) >= 0 && (p3-p0).norm <= (p1-p0).norm )
puts 1
elsif ( cross(p3-p2, p0-p2) == 0 && (p3-p2).inner_product(p0-p2) >= 0 && (p0-p2).norm <= (p3-p2).norm ) ||
( cross(p3-p2, p1-p2) == 0 && (p3-p2).inner_product(p1-p2) >= 0 && (p1-p2).norm <= (p3-p2).norm )
puts 1
else
puts 0
end
end
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 128,119
| 128,120
|
u352522848
|
ruby
|
p02314
|
def solution(n, m, coins)
dp = [0] + [Float::INFINITY] * n
for coin in coins
for amount in 0..n
if amount >= coin
dp[amount] = [dp[amount], dp[amount - coin] + 1].min
else
dp[amount] = dp[amount]
end
end
p dp
end
dp[n]
end
first_line = gets.split.map(&:to_i)
coins = gets.split.map(&:to_i)
p solution(first_line[0], first_line[1], coins)
|
def solution(n, m, coins)
dp = [0] + [Float::INFINITY] * n
for coin in coins
for amount in 0..n
if amount >= coin
dp[amount] = [dp[amount], dp[amount - coin] + 1].min
else
dp[amount] = dp[amount]
end
end
end
dp[n]
end
first_line = gets.split.map(&:to_i)
coins = gets.split.map(&:to_i)
p solution(first_line[0], first_line[1], coins)
|
[
"call.remove"
] | 128,767
| 128,768
|
u854817684
|
ruby
|
p02315
|
def solve_knapsack(w, v, q)
n = w.length
inf = 1e9.to_i
ans = [-inf] * (q + 1)
ans[0] = 0
(w.zip(v)).each do |wi, vi|
(0..(q-wi)).each do |kkk|
k = (q-wi) - kkk
ans[k+wi] = [ans[k+wi], ans[k] + vi].max
end
end
ans[q]
end
if __FILE__ == $0
n, q = gets().split().map(&:to_i)
v, w = [], []
n.times do |i|
vi, wi = gets().split().map(&:to_i)
v << vi
w << wi
end
a = solve_knapsack(w, v, q)
puts a
#w = [3,2,4,1,3]
#v = [2,3,3,2,6]
#q = 10
#a = solve_knapsack(w, v, q)
#puts "ans: #{a}"
end
|
def solve_knapsack(w, v, q)
n = w.length
inf = 1e9.to_i
ans = [-inf] * (q + 1)
ans[0] = 0
(w.zip(v)).each do |wi, vi|
(0..(q-wi)).each do |kkk|
k = (q-wi) - kkk
ans[k+wi] = [ans[k+wi], ans[k] + vi].max
end
end
ans.max
end
if __FILE__ == $0
n, q = gets().split().map(&:to_i)
v, w = [], []
n.times do |i|
vi, wi = gets().split().map(&:to_i)
v << vi
w << wi
end
a = solve_knapsack(w, v, q)
puts a
#w = [3,2,4,1,3]
#v = [2,3,3,2,6]
#q = 10
#a = solve_knapsack(w, v, q)
#puts "ans: #{a}"
end
|
[] | 129,185
| 129,186
|
u890256830
|
ruby
|
p02317
|
n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp = Array.new
dp << -1
n.times do |i|
if dp.last < a[i]
dp << a[i]
else
left = 0
right = dp.size
mid = 0
while left <= right
mid = (left + right)/2
if a[i] >= dp[mid]
left = mid + 1
else
right = mid - 1
end
end
if dp[right] < a[i] && dp[right+1] > a[i]
dp[right+1] = a[i]
end
end
end
p dp.size - 1
|
n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp = Array.new
dp << -1
n.times do |i|
if dp.last < a[i]
dp << a[i]
else
left = 0
right = dp.size - 1
mid = 0
while left <= right
mid = (left + right)/2
if a[i] >= dp[mid]
left = mid + 1
else
right = mid - 1
end
end
if dp[right] < a[i] && dp[right+1] > a[i]
dp[right+1] = a[i]
end
end
end
p dp.size - 1
|
[
"assignment.change"
] | 130,558
| 130,559
|
u811434779
|
ruby
|
p02317
|
n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp = Array.new
dp << -1
n.times do |i|
if dp.last < a[i]
dp << a[i]
else
left = 0
right = dp.size
mid = 0
while left <= right
mid = (left + right)/2
if a[i] >= dp[mid]
left = mid + 1
else
right = mid - 1
end
end
if dp[right] < a[i] && dp[right+1] > a[i]
dp[right+1] = a[i]
end
end
end
p dp.size - 1
|
n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp = Array.new
dp << -1
n.times do |i|
if dp.last < a[i]
dp << a[i]
else
left = 0
right = dp.size - 1
mid = 0
while left <= right
mid = (left + right)/2
if a[i] >= dp[mid]
left = mid + 1
else
right = mid - 1
end
end
if dp[right] < a[i] && dp[left] > a[i]
dp[right+1] = a[i]
end
end
end
p dp.size - 1
|
[
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 130,558
| 130,560
|
u811434779
|
ruby
|
p02318
|
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new()
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
matrix[0][i] = i
end
for i in 1..lenStr2 do
matrix[i][0] = i
end
for i in 1..lenStr1 do
for j in 1..lenStr2 do
x = (str1[j-1] == str2[i-1]) ? 0 : 1
y = matrix[j][i-1] + 1
z = matrix[j-1][i] + 1
matrix[j][i] = [matrix[j-1][i-1]+x, y, z].min
end
end
print("#{matrix[lenStr2][lenStr1]}\n")
|
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new()
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
matrix[0][i] = i
end
for i in 1..lenStr2 do
matrix[i][0] = i
end
for i in 1..lenStr1 do
for j in 1..lenStr2 do
x = (str1[i-1] == str2[j-1]) ? 0 : 1
y = matrix[j][i-1] + 1
z = matrix[j-1][i] + 1
matrix[j][i] = [matrix[j-1][i-1]+x, y, z].min
end
end
print("#{matrix[lenStr2][lenStr1]}\n")
|
[
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 130,747
| 130,748
|
u199171255
|
ruby
|
p02318
|
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new()
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
matrix[0][i] = i
end
for i in 1..lenStr2 do
matrix[i][0] = i
end
for i in 1..lenStr1 do
for j in 1..lenStr2 do
x = (str1[j-1] == str2[i-1]) ? 0 : 1
y = matrix[j][i-1] + 1
z = matrix[j-1][i] + 1
matrix[j][i] = [matrix[j-1][i-1]+x, y, z].min
end
end
print("#{matrix[lenStr2][lenStr1]}\n")
|
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
matrix[0][i] = i
end
for i in 1..lenStr2 do
matrix[i][0] = i
end
for i in 1..lenStr1 do
for j in 1..lenStr2 do
x = (str1[i-1] == str2[j-1]) ? 0 : 1
y = matrix[j][i-1] + 1
z = matrix[j-1][i] + 1
matrix[j][i] = [matrix[j-1][i-1]+x,y,z].min
end
end
print("#{matrix[lenStr2][lenStr1]}\n")
|
[
"call.arguments.change",
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 130,747
| 130,749
|
u199171255
|
ruby
|
p02318
|
s1 = gets.chomp
s2 = gets.chomp
# s1???????????°???[0..s1.size]?????£?????´???
# s2???????????°???[0..s2.size]?????£?????´???
# ??¨???????????????
res = Array.new(s1.size.succ).map{Array.new(s2.size.succ, 0)}
# ????????????????????????0???????????¨????????¢?????????????????????
for i in (0..s1.size) do
res[i][0] = i
end
for i in (0..s2.size) do
res[0][i] = i
end
# ??¨????????????????????????????????°??¨????????¢???1????????¨??????
# ????????§???????????°??¨????????¢???1?¢???????
for i in (1..s1.size) do
for j in (1..s2.size) do
if s1[i] == s2[j]
res[i][j] = res[i - 1][j - 1]
else
res[i][j] = [res[i - 1][j - 1], res[i - 1][j], res[i][j - 1]].min + 1
end
end
end
p res[s1.size][s2.size]
|
s1 = gets.chomp
s2 = gets.chomp
# s1???????????°???[0..s1.size]?????£?????´???
# s2???????????°???[0..s2.size]?????£?????´???
# ??¨???????????????
res = Array.new(s1.size.succ).map{Array.new(s2.size.succ, 0)}
# ????????????????????????0???????????¨????????¢?????????????????????
for i in (0..s1.size) do
res[i][0] = i
end
for i in (0..s2.size) do
res[0][i] = i
end
# ??¨????????????????????????????????°??¨????????¢???1????????¨??????
# ????????§???????????°??¨????????¢???1?¢???????
# ???????????????s??¨dp???????????????1????????????
for i in (1..s1.size) do
for j in (1..s2.size) do
if s1[i - 1] == s2[j - 1]
res[i][j] = res[i - 1][j - 1]
else
res[i][j] = [res[i - 1][j - 1], res[i - 1][j], res[i][j - 1]].min + 1
end
end
end
p res[s1.size][s2.size]
|
[
"control_flow.branch.if.condition.change"
] | 130,750
| 130,751
|
u645879095
|
ruby
|
p02346
|
# range_sum_query
#
#
s=STDIN.gets.split
n = s[0].to_i
q = s[1].to_i
ar = Array.new(100001,0)
ar2 = Array.new(1001 ,0)
1.upto(q) {
s=STDIN.gets.split
com = s[0].to_i
x = s[1].to_i
y = s[2].to_i
#printf(":%d %d %d\n",com,x,y)
if(com==0)
x1=x/100
diff = y - ar[x]
ar[x]=y
ar2[x1] += diff
elsif (com==1)
x1=x/100
y1=y/100
ans_=0
if(x1==y1 || x1+1==y1)
x.upto(y){|i|
ans_ += ar[i]
}
else
if (x % 100) > 0 then
x.upto(x1*100+99){|i| ans_ += ar[i] }
(x1+1).upto(y1-1){|i| ans_ += ar2[i] }
else
x1.upto(y1-1){|i| ans_ += ar2[i] }
end
(y1*100).upto(y){|i| ans_ += ar[i] }
end
puts ans_
end
}
|
# range_sum_query
#
#
s=STDIN.gets.split
n = s[0].to_i
q = s[1].to_i
ar = Array.new(100001,0)
ar2 = Array.new(1001 ,0)
1.upto(q) {
s=STDIN.gets.split
com = s[0].to_i
x = s[1].to_i
y = s[2].to_i
#printf(":%d %d %d\n",com,x,y)
if(com==0)
x1=x/100
diff = y - ar[x]
ar[x] += y
ar2[x1] += y
elsif (com==1)
x1=x/100
y1=y/100
ans_=0
if(x1==y1 || x1+1==y1)
x.upto(y){|i|
ans_ += ar[i]
}
else
if (x % 100) > 0 then
x.upto(x1*100+99){|i| ans_ += ar[i] }
(x1+1).upto(y1-1){|i| ans_ += ar2[i] }
else
x1.upto(y1-1){|i| ans_ += ar2[i] }
end
(y1*100).upto(y){|i| ans_ += ar[i] }
end
puts ans_
end
}
|
[
"assignment.value.change",
"identifier.change"
] | 131,330
| 131,331
|
u708993917
|
ruby
|
p02346
|
def add(a, b, k, l, r, node)
return 0 if r <= a || b <= l
return node[k] if a <= l && r <= b
m = (l+r)/2
vl = add(a, b, 2*k+1, l, m, node)
vr = add(a, b, 2*k+2, m, r, node)
return vl + vr
end
n, q = gets.split.map(&:to_i)
m = 1
while m < n
m *= 2
end
node = Array.new(2*m-1){0}
q.times{
com, x, y = gets.split.map(&:to_i)
x -= 1
case com
when 0
k = x + m - 1
node[k] += y
while k > 0
k = (k-1)/2
node[k] += y
end
when 1
puts add(x, y+1, 0, 0, m, node)
end
}
|
def add(a, b, k, l, r, node)
return 0 if r <= a || b <= l
return node[k] if a <= l && r <= b
m = (l+r)/2
vl = add(a, b, 2*k+1, l, m, node)
vr = add(a, b, 2*k+2, m, r, node)
return vl + vr
end
n, q = gets.split.map(&:to_i)
m = 1
while m < n
m *= 2
end
node = Array.new(2*m-1){0}
q.times{
com, x, y = gets.split.map(&:to_i)
x -= 1
case com
when 0
k = x + m - 1
node[k] += y
while k > 0
k = (k-1)/2
node[k] += y
end
when 1
puts add(x, y, 0, 0, m, node)
end
}
|
[
"expression.operation.binary.remove"
] | 131,334
| 131,335
|
u960312159
|
ruby
|
p02345
|
class SegmentTree
def initialize
@N=2**17
@INF=2**32-1
@seg=Array.new(2*@N-1){@INF}
end
def update(i, x)
i+=@N-1 #??°??????i??????????????????????????¨????????????????????????
@seg[i]=x
while i.nonzero?
i=(i-1)/2 #????????????????????????????????¨????????????
@seg[i]=[@seg[2*i+1], @seg[2*i+2]].min #????????????
end
end
def segmin(a, b, i=0, l=0, r=@N) #??????i?????????????????????=>[l, r)
if b<=l or r<=a #2??????????????????????????????; ??\???????????????????????´
@INF
elsif a<=l and r<=b #????????????????????¨?????\??????????????????????????????
@seg[i]
else
m=(l+r)/2
vl=segmin(a, b, 2*i+1, l, m) #?????????
vr=segmin(a, b, 2*i+2, m, r) #?????????
[vl, vr].min
end
end
end
n, q=gets.split.map(&:to_i)
st=SegmentTree.new
q.times do |i|
c, a, b=gets.split.map(&:to_i)
case c
when 0 #update a-th element to b
st.update(a, b)
when 1 #getmin [a..b]
puts st.segmin(a, b)
end
end
|
class SegmentTree
def initialize
@N=2**17
@INF=2**31-1
@seg=Array.new(2*@N-1){@INF}
end
def update(i, x)
i+=@N-1 #??°??????i??????????????????????????¨????????????????????????
@seg[i]=x
while i.nonzero?
i=(i-1)/2 #????????????????????????????????¨????????????
@seg[i]=[@seg[2*i+1], @seg[2*i+2]].min #????????????
end
end
def segmin(a, b, i=0, l=0, r=@N) #??????i?????????????????????=>[l, r)
if b<=l or r<=a #2??????????????????????????????; ??\???????????????????????´
@INF
elsif a<=l and r<=b #????????????????????¨?????\??????????????????????????????
@seg[i]
else
m=(l+r)/2
vl=segmin(a, b, 2*i+1, l, m) #?????????
vr=segmin(a, b, 2*i+2, m, r) #?????????
[vl, vr].min
end
end
end
n, q=gets.split.map(&:to_i)
st=SegmentTree.new
q.times do |i|
c, a, b=gets.split.map(&:to_i)
case c
when 0 #update a-th element to b
st.update(a, b)
when 1 #getmin [a..b]
puts st.segmin(a, b+1)
end
end
|
[
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 131,338
| 131,339
|
u677070142
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.chomp.split.map(&:to_i)
d = Math.sqrt((x2-x1)**2 + (y2-y1)**2)
puts d
|
x1,y1,x2,y2 = gets.chomp.split.map(&:to_f)
d = Math.sqrt((x2-x1)**2 + (y2-y1)**2)
puts d
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,794
| 134,795
|
u742797815
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.chomp.split.map(&:to_i)
d = Math.sqrt((x2-x1)**2 + (y2-y1)**2)
puts d
|
x1,y1,x2,y2 = gets.chomp.split.map(&:to_r)
d = Math.sqrt((x2-x1)**2 + (y2-y1)**2)
puts d
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,794
| 134,796
|
u742797815
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split(" ").map{|x| x.to_i}
puts Math::sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
x1, y1, x2, y2 = gets.split(" ").map{|x| x.to_f}
puts Math::sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change"
] | 134,797
| 134,798
|
u364560197
|
ruby
|
p02379
|
(x1,y1,x2,y2)=gets.split.map(&:to_i)
x=x2-x1
y=y2-y1
puts Math.sqrt(x**2+y**2)
|
(x1,y1,x2,y2)=gets.split.map(&:to_f)
x=x2-x1
y=y2-y1
puts Math.sqrt(x**2+y**2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,799
| 134,800
|
u565102293
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts sprintf("%.5f\n", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts sprintf("%f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
[
"assignment.value.change",
"call.arguments.change",
"literal.string.change",
"io.output.change",
"io.output.newline.remove"
] | 134,804
| 134,805
|
u873778695
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts sprintf("%.5f\n", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts sprintf("%f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
[
"assignment.value.change",
"call.arguments.change",
"literal.string.change",
"io.output.change",
"io.output.newline.remove"
] | 134,806
| 134,805
|
u873778695
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts sprintf("%.5f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts sprintf("%f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
[
"assignment.value.change",
"call.arguments.change",
"literal.string.change",
"io.output.change"
] | 134,807
| 134,805
|
u873778695
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts sprintf("%f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts sprintf("%f", ((x2-x1)**2 + (y2-y1)**2)**(1/2.0))
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,808
| 134,805
|
u873778695
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split( " " ).map { |val| val.to_i }
puts( Math.sqrt( ( x1 - x2 )**2 + ( y1 - y2 )**2 ) )
|
x1, y1, x2, y2 = gets.split( " " ).map { |val| val.to_f }
puts( Math.sqrt( ( x1 - x2 )**2 + ( y1 - y2 )**2 ) )
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change"
] | 134,809
| 134,810
|
u604774382
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts Math.sqrt((x1 - x2)**2 + (y1 -y2)**2)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts Math.sqrt((x1 - x2)**2 + (y1 -y2)**2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,811
| 134,812
|
u209022771
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a + b)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a + b)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,813
| 134,814
|
u330842660
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts a
puts Math.sqrt(a + b)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a + b)
|
[
"call.remove"
] | 134,815
| 134,814
|
u330842660
|
ruby
|
p02379
|
x1,y1,x2,y2=gets.split.map(&:to_i)
d=((x2-x1)**2+(y2-y1)**2)**(1/2.0)
puts "%05f" % d
|
x1,y1,x2,y2=gets.split.map(&:to_f)
d=((x2-x1)**2+(y2-y1)**2)**(1/2.0)
puts "%05f" % d
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,816
| 134,817
|
u352522848
|
ruby
|
p02379
|
include Math
x1,y1,x2,y2= gets.split.map(&:to_i)
dx = x1 - x2
dy = y1 - y2
puts sqrt(dx * dx + dy * dy)
|
include Math
x1,y1,x2,y2= gets.split.map(&:to_f)
dx = x1 - x2
dy = y1 - y2
puts sqrt(dx * dx + dy * dy)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,818
| 134,819
|
u043406421
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)
x_long = x2 - x1
y_long = y2 - y1
long = Math.hypot(x_long, y_long)
puts "#{sprintf("%.9f", long)}"
|
x1, y1, x2, y2 = gets.chomp.split.map(&:to_f)
x_long = x2 - x1
y_long = y2 - y1
long = Math.hypot(x_long, y_long)
puts "#{sprintf("%.9f", long)}"
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,820
| 134,821
|
u960296069
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_i)
puts sprintf("%.5f", Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts sprintf("%.5f", Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,824
| 134,823
|
u750346935
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.split.map(&:to_i)
printf "%.8f\n", Math.hypot(x1 - x2, y1 - y2)
|
x1,y1,x2,y2 = gets.split.map(&:to_f)
printf "%.8f\n", Math.hypot(x1 - x2, y1 - y2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,825
| 134,826
|
u709642619
|
ruby
|
p02379
|
x1, y1, x2, y2 = STDIN.gets.split(" ").map(&:to_i)
puts "%.8f" % [((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5]
|
x1, y1, x2, y2 = STDIN.gets.split(" ").map(&:to_f)
puts "%.8f" % [((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5]
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,827
| 134,828
|
u854587684
|
ruby
|
p02379
|
a = gets.split(" ").map(&:to_i);
x = a[2] - a[0];
y = a[3] - a[1];
puts ((x**2 + y**2)**0.5).to_s;
|
a = gets.split(" ").map(&:to_f);
x = a[2] - a[0];
y = a[3] - a[1];
puts ((x**2 + y**2)**0.5).to_s;
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,829
| 134,830
|
u328069918
|
ruby
|
p02379
|
x1,x2,y1,y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a+b)
|
x1,y1,x2,y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a+b)
|
[] | 134,838
| 134,839
|
u407138207
|
ruby
|
p02379
|
x1,x2,y1,y2 = gets.split.map(&:to_f)
a = (x2 - x1)**2
b = (y2 - y1)**2
puts Math.sqrt(a+b)
|
x1,y1,x2,y2 = gets.split.map(&:to_f)
a = (x2 - x1) **2
b = (y2 - y1) **2
puts Math.sqrt(a+b)
|
[] | 134,838
| 134,840
|
u407138207
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.split.map(&:to_f)
a = (x2 - x1) **2
b = (y2 - y1) **2
puts Math.sprt(a+b)
|
x1,y1,x2,y2 = gets.split.map(&:to_f)
a = (x2 - x1) **2
b = (y2 - y1) **2
puts Math.sqrt(a+b)
|
[
"identifier.change",
"call.arguments.change",
"io.output.change"
] | 134,841
| 134,840
|
u407138207
|
ruby
|
p02379
|
def calc_distance(x, y) #x, y???????´???°2??????1?¬??????????
require 'bigdecimal'
distance = ((y[0] - x[0])**2 + (y[1] - x[1])**2) ** 0.5
distance_approximately = BigDecimal(distance.to_s).floor(8).to_f
return distance_approximately #P1??¨P2????????¢
end
input_values = gets.chomp.split.map(&:to_i)
x = [input_values[0], input_values[1]]
y = [input_values[2], input_values[3]]
puts calc_distance(x, y)
|
def calc_distance(x, y) #x, y???????´???°2??????1?¬??????????
require 'bigdecimal'
distance = ((y[0] - x[0])**2 + (y[1] - x[1])**2) ** 0.5
distance_approximately = BigDecimal(distance.to_s).floor(8).to_f
return distance_approximately #P1??¨P2????????¢
end
input_values = gets.chomp.split.map(&:to_f)
x = [input_values[0], input_values[1]]
y = [input_values[2], input_values[3]]
puts calc_distance(x, y)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,842
| 134,843
|
u723368439
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.split(" ").map(&:to_i)
distance = (x2-x1)**2 + (y2-y1)**2
puts Math.sqrt(distance)
|
x1,y1,x2,y2 = gets.split(" ").map(&:to_f)
distance = (x2-x1)**2 + (y2-y1)**2
puts Math.sqrt(distance)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,844
| 134,845
|
u501176275
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts Math.sqrt((x2 - x1) ** 2 + (y1 + y2) ** 2)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
[
"expression.operation.binary.remove",
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 134,846
| 134,847
|
u802537549
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split(" ").map(&:to_i)
a = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
puts "%f"%a
|
x1, y1, x2, y2 = gets.split(" ").map(&:to_f)
a = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
puts "%f"%a
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,850
| 134,851
|
u906710658
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split(" ").map(&:to_i)
printf "%f\n", Math.sqrt((x2-x1)**2 + (y2-y1)**2)
|
x1, y1, x2, y2 = gets.split(" ").map(&:to_f)
printf "%f\n", Math.sqrt((x2-x1)**2 + (y2-y1)**2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,852
| 134,853
|
u960312159
|
ruby
|
p02379
|
a, b, c, d = gets.split.map(&:to_i)
p Math.hypot(c - a, d - b)
|
a, b, c, d = gets.split.map(&:to_f)
p Math.hypot(c - a, d - b)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,854
| 134,855
|
u295404099
|
ruby
|
p02379
|
#!/usr/bin/env ruby
x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)
puts Math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
|
#!/usr/bin/env ruby
x1, y1, x2, y2 = gets.chomp.split.map(&:to_f)
puts Math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,856
| 134,857
|
u717782380
|
ruby
|
p02379
|
# Your code here!
x1, y1, x2, y2 = gets.split.map(&:to_i)
p ((x2 - x1)**2 + (y2 - y1)**2) **(1/2.0)
|
# Your code here!
x1, y1, x2, y2 = gets.split.map(&:to_f)
puts ((x2 - x1)**2 + (y2 - y1)**2)**(1/2.0)
|
[
"assignment.value.change",
"call.arguments.change",
"call.function.change",
"io.output.change"
] | 134,858
| 134,859
|
u401720175
|
ruby
|
p02379
|
x1,y1,x2,y2 = gets.chomp.split(" ").map{|x| x.to_i}
printf("%f\n",((x2-x1)**2+(y2-y1)**2)**0.5)
|
x1,y1,x2,y2 = gets.chomp.split(" ").map{|x| x.to_f}
printf("%f\n",((x2-x1)**2+(y2-y1)**2)**0.5)
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change"
] | 134,860
| 134,861
|
u241079749
|
ruby
|
p02379
|
x1, y1, x2, y2 = gets.split.to_f
printf "%.4f", Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
printf "%.4f", Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
[
"assignment.value.change",
"identifier.change",
"call.arguments.add"
] | 134,864
| 134,865
|
u864617427
|
ruby
|
p02379
|
x1, y1, x2, y2 = io.gets.split.map(&:to_f)
printf "%.4f", Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
x1, y1, x2, y2 = gets.split.map(&:to_f)
printf "%.4f", Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
|
[
"call.remove"
] | 134,866
| 134,865
|
u864617427
|
ruby
|
p02379
|
a,b,c,d=gets.split.map(&:to_i)
puts Math.sqrt((c-a)**2+(d-b)**2)
|
a,b,c,d=gets.split.map(&:to_f)
puts Math.sqrt((c-a)**2+(d-b)**2)
|
[
"assignment.value.change",
"call.arguments.change"
] | 134,867
| 134,868
|
u517414491
|
ruby
|
p02381
|
while (n=gets.to_i)!=0
s=gets.split.map &:to_i
p (s.inject(0){|a,i|a+(i-(eval s*?+)/n)**2}/n)**0.5
end
|
while (n=gets.to_i)!=0
s=gets.split.map &:to_f
p (s.inject(0){|a,i|a+(i-(eval s*?+)/n)**2}/n)**0.5
end
|
[
"assignment.value.change",
"call.arguments.change"
] | 136,269
| 136,270
|
u550290469
|
ruby
|
p02381
|
loop do
sigma = 0
n = gets.to_i
exit 0 if n == 0
s = gets.split(" ").map{|x| x.to_i}
for i in 0..(s.length - 1)
sigma += (s[i] - (s.inject(:+) / s.length)) ** 2
end
puts Math::sqrt(sigma / n)
end
|
loop do
sigma = 0
n = gets.to_i
exit 0 if n == 0
s = gets.split(" ").map{|x| x.to_i}
for i in 0..(s.length - 1)
sigma += (s[i] - (s.inject(:+).to_f / s.length)) ** 2
end
puts Math::sqrt(sigma / n)
end
|
[
"call.add"
] | 136,273
| 136,274
|
u364560197
|
ruby
|
p02381
|
def getAverage(points)
sum = 0
points.each {|x|
sum += x
}
return (sum / points.length).to_f
end
while true
n = STDIN.gets.to_i
if n == 0 then break end
str = STDIN.gets.split(" ")
point = Array.new(n) { |i| i = str[i].to_i}
average = getAverage(point)
s = 0.0
for i in 0..point.length - 1 do
s += (point[i] - average) * (point[i] - average)
end
s = Math.sqrt(s / n)
puts sprintf("%.5f", s)
end
|
def getAverage(points)
sum = 0
points.each {|x|
sum += x
}
return (sum / points.length).to_f
end
while true
n = STDIN.gets.to_i
if n == 0 then break end
str = STDIN.gets.split(" ")
point = Array.new(n) { |i| i = str[i].to_f}
average = getAverage(point)
s = 0.0
for i in 0..point.length - 1 do
s += (point[i] - average) * (point[i] - average)
end
s = Math.sqrt(s / n)
puts sprintf("%.5f", s)
end
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change"
] | 136,275
| 136,276
|
u938745275
|
ruby
|
p02381
|
loop do
n = gets.chomp.to_i
if n == 0
break
end
s = gets.split
i = 0
s.each do |j|
i += j.to_i
end
m = i / n
k = 0
s.each do |l|
k += (l.to_i - m) ** 2
end
a = k / n
puts "#{sprintf("%.9f", Math.sqrt(a))}"
end
|
loop do
n = gets.chomp.to_i
if n == 0
break
end
s = gets.split
i = 0
s.each do |j|
i += j.to_f
end
m = i / n
k = 0
s.each do |l|
k += (l.to_i - m) ** 2
end
a = k / n
puts "#{sprintf("%.9f", Math.sqrt(a))}"
end
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change"
] | 136,280
| 136,281
|
u960296069
|
ruby
|
p02381
|
until (n = gets.chomp.to_i) == 0
arr = gets.split.map(&:to_i)
sum = 0
n.times do |i|
sum = sum + arr[i]
end
ave = sum / n
alpha = 0
n.times do |i|
alpha = alpha + ((arr[i] - ave)**2)
end
puts (alpha / n) ** 0.5
end
|
until (n = gets.chomp.to_i) == 0
arr = gets.split.map(&:to_i)
sum = 0
n.times do |i|
sum = sum + arr[i]
end
ave = sum.to_f / n
alpha = 0
n.times do |i|
alpha = alpha + ((arr[i] - ave)**2)
end
puts (alpha / n) ** 0.5
end
|
[
"call.add"
] | 136,284
| 136,285
|
u261074410
|
ruby
|
p02381
|
while n = gets.to_i
break if n.zero?
students = gets.split.map(&:to_i)
average = students.inject(&:+) / n
dispersion = students.inject(0) { |sum, num| sum + (num - average)**2 } / n
puts Math.sqrt(dispersion)
end
|
while n = gets.to_i
break if n.zero?
students = gets.split.map(&:to_i)
average = students.inject(&:+) / n.to_f
dispersion = students.inject(0) { |sum, num| sum + (num - average)**2 } / n
puts Math.sqrt(dispersion)
end
|
[
"call.add"
] | 136,286
| 136,287
|
u139670451
|
ruby
|
p02381
|
while gets != "0\n"
ss = gets.split.map(&:to_i)
ave = ss.inject(:+) / ss.size
puts Math.sqrt(ss.map{|s|(s-ave)**2}.inject(:+)/ss.size)
end
|
while gets != "0\n"
ss = gets.split.map(&:to_f)
ave = ss.inject(:+) / ss.size
puts Math.sqrt(ss.map{|s|(s-ave)**2}.inject(:+)/ss.size)
end
|
[
"assignment.value.change",
"call.arguments.change"
] | 136,288
| 136,289
|
u422350156
|
ruby
|
p02381
|
until ((n = gets.chomp.to_i) == 0)
numbers = gets.chomp.split.map(&:to_f)
squares = numbers.map{|n| n ** 2}
sum = numbers.inject(:+) / n
ss = squares.inject(:+)
sd = Math.sqrt(ss / n - mean ** 2)
printf("%.5f\n", sd)
end
|
until ((n = gets.chomp.to_i) == 0)
numbers = gets.chomp.split.map(&:to_f)
squares = numbers.map{|n| n ** 2}
mean = numbers.inject(:+) / n
ss = squares.inject(:+)
sd = Math.sqrt(ss / n - mean ** 2)
printf("%.5f\n", sd)
end
|
[
"assignment.variable.change",
"identifier.change"
] | 136,290
| 136,291
|
u247371045
|
ruby
|
p02381
|
until ((n = gets.chomp.to_i) == 0)
numbers = gets.chomp.split.map(&:to_i)
mean = numbers.inject(:+) / n.to_f
squares = numbers.map{|n| n ** 2}
ss = squares.inject(:+)
sd = Math.sqrt(ss / n - mean ** 2)
printf("%.5f\n", sd)
end
|
until ((n = gets.chomp.to_i) == 0)
numbers = gets.chomp.split.map(&:to_i)
mean = numbers.inject(:+) / n.to_f
squares = numbers.map{|n| n ** 2}
ss = squares.inject(:+)
sd = Math.sqrt(ss / n.to_f - mean ** 2)
printf("%.5f\n", sd)
end
|
[
"call.add"
] | 136,292
| 136,293
|
u247371045
|
ruby
|
p02381
|
while n = gets.chomp.to_i
if n==0
break
end
s = gets.chomp.split(" ").map{|item| item.to_i}
ave=0
n.times{ |idx|
ave += s[idx]
}
ave/=n
a=0
n.times{ |idx|
a+=(s[idx]-ave)**2
}
a/=n
a=Math::sqrt(a)
puts a
end
|
while n = gets.chomp.to_i
if n==0
break
end
s = gets.chomp.split(" ").map{|item| item.to_i}
ave=0.0
n.times{ |idx|
ave += s[idx]
}
ave/=n
a=0.0
n.times{ |idx|
a+=(s[idx]-ave)**2
}
a/=n
a=Math::sqrt(a)
puts a
end
|
[
"assignment.value.change"
] | 136,294
| 136,295
|
u843848664
|
ruby
|
p02381
|
while true do
count = gets.to_i;
if count == 0 then
break;
end
sum = 0.to_f;
average = 0.to_f;
aryStudentPoint = gets.split(' ').map(&:to_f);
for sumIndex in 0..aryStudentPoint.length - 1 do
sum = sum + aryStudentPoint[sumIndex];
end
average = sum / average;
sum = 0.to_f;
for index in 0..aryStudentPoint.length - 1 do
sum = sum + (aryStudentPoint[index] - average) * (aryStudentPoint[index] - average)
end
puts "%.8f" % Math.sqrt(sum / count)
end
|
while true do
count = gets.to_i;
if count == 0 then
break;
end
sum = 0.to_f;
average = 0.to_f;
aryStudentPoint = gets.split(' ').map(&:to_f);
for sumIndex in 0..aryStudentPoint.length - 1 do
sum = sum + aryStudentPoint[sumIndex];
end
average = sum / count;
sum = 0.to_f;
for index in 0..aryStudentPoint.length - 1 do
sum = sum + (aryStudentPoint[index] - average) * (aryStudentPoint[index] - average)
end
puts "%.8f" % Math.sqrt(sum / count)
end
|
[
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change"
] | 136,296
| 136,297
|
u606593727
|
ruby
|
p02381
|
while (times = gets.to_i) != 0
date = gets.split(" ").map(&:to_i)
ave = date.inject(:+) / times
sum = 0
for i in 0...times
sum += (date[i]-ave)**2
end
s = Math.sqrt(sum/times)
puts s
end
|
while (times = gets.to_f) != 0
date = gets.split(" ").map(&:to_f)
ave = date.inject(:+) / times
sum = 0
for i in 0...times
sum += (date[i]-ave)**2
end
s = Math.sqrt(sum/times)
puts s
end
|
[
"call.function.change",
"type_conversion.to_float.change",
"type_conversion.to_number.change",
"assignment.value.change",
"call.arguments.change"
] | 136,298
| 136,299
|
u501176275
|
ruby
|
p02381
|
while n = gets.to_i do
break if n == 0
s = gets.split(" ").map(&:to_i)
m = s.inject(:+)/n
s2 = 0
s.each{|si|
s2 += (si - m)**2
}
printf "%f\n", Math.sqrt(s2 / n)
end
|
while n = gets.to_i do
break if n == 0
s = gets.split(" ").map(&:to_i)
m = s.inject(:+)/n.to_f
s2 = 0
s.each{|si|
s2 += (si - m)**2
}
printf "%f\n", Math.sqrt(s2 / n)
end
|
[
"call.add"
] | 136,300
| 136,301
|
u960312159
|
ruby
|
p02380
|
include Math
def f(a, b, c)
return (0.5 * a * b * sin(g(c))), (a ** 2 + b ** 2 - 2 * a * b * cos(g(c))) ** 0.5 * a + b, b * sin(g(c))
end
def g(c)
return c * PI / 180
end
puts f(*gets.split(" ").map(&:to_i))
|
include Math
def f(a, b, c)
return (0.5 * a * b * sin(g(c))), (a ** 2 + b ** 2 - 2 * a * b * cos(g(c))) ** 0.5 + a + b, b * sin(g(c))
end
def g(c)
return c * PI / 180
end
puts f(*gets.split(" ").map(&:to_i))
#f(*gets.split(" ").map(&:to_i)).each{|i|puts sprintf("%.4f", i)}
|
[
"expression.operator.arithmetic.change",
"call.arguments.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 136,304
| 136,305
|
u514597327
|
ruby
|
p02380
|
a, b, c = gets.split.map(&:to_f)
s = 0.5 * (a * b) * (Math.sin(c * (Math::PI / 180)))
l = a + b + Math.sqrt(a**2 + b**2 + (2 * a * b * Math.cos(c * (Math::PI / 180))))
h = b * Math.sin(c * (Math::PI / 180.0))
puts s
puts l
puts h
|
a, b, c = gets.split.map(&:to_f)
s = 0.5 * (a * b) * (Math.sin(c * (Math::PI / 180)))
l = a + b + Math.sqrt(a**2 + b**2 - (2 * a * b * Math.cos(c * (Math::PI / 180))))
h = b * Math.sin(c * (Math::PI / 180))
puts s
puts l
puts h
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 136,306
| 136,307
|
u330842660
|
ruby
|
p02380
|
a,b,c=gets.split.map(&:to_f)
h=b*Math.sin(Math::PI*c/180)
puts a*h*1/2
puts a+b+(h**2+(a-b*Math.cos(Math::PI*c/180))**2)**(1/2.0)
|
a,b,c=gets.split.map(&:to_f)
h=b*Math.sin(Math::PI*c/180)
puts a*h*1/2
puts a+b+(h**2+(a-b*Math.cos(Math::PI*c/180))**2)**(1/2.0)
puts h
|
[
"call.add"
] | 136,308
| 136,309
|
u352522848
|
ruby
|
p02380
|
a, b, c = gets.split.map(&:to_f)
h = sin(c *= PI / 180) * b
puts a / 2 * h
puts a + b + sqrt(a * a + b * b - 2 * a * b * cos(c))
puts h
|
include Math
a, b, c = gets.split.map(&:to_f)
h = sin(c *= PI / 180) * b
puts a / 2 * h
puts a + b + sqrt(a * a + b * b - 2 * a * b * cos(c))
puts h
|
[
"call.add"
] | 136,310
| 136,311
|
u364253163
|
ruby
|
p02380
|
a, b, theta = gets.chomp.split.map(&:to_f)
rad = theta / 180 * Math::PI
h = b * Math.sin(rad)
S = a * h / 2
c = Math.sqrt(a ** 2 + b **2 - a * b * Math.cos(rad))
L = a + b + c
printf("%.5f\n", S)
printf("%.5f\n", L)
printf("%.5f\n", h)
|
a, b, theta = gets.chomp.split.map(&:to_f)
rad = theta / 180 * Math::PI
h = b * Math.sin(rad)
S = a * h / 2
c = Math.sqrt(a ** 2 + b **2 - 2 * a * b * Math.cos(rad))
L = a + b + c
printf("%.5f\n", S)
printf("%.5f\n", L)
printf("%.5f\n", h)
|
[
"assignment.change"
] | 136,314
| 136,315
|
u247371045
|
ruby
|
p02380
|
#!/usr/bin/env ruby
a, b, c = gets.chomp.split.map(&:to_f)
c_rad = c * Math::PI / 180
l = Math.sqrt(a**2 + b**2 + a * b * Math.cos(c_rad)) + a + b
h = b * Math.sin(c_rad)
s = a * h / 2
puts s, l, h
|
#!/usr/bin/env ruby
a, b, c = gets.chomp.split.map(&:to_f)
c_rad = c * Math::PI / 180
l = Math.sqrt(a**2 + b**2 - 2 * a * b * Math.cos(c_rad)) + a + b
h = b * Math.sin(c_rad)
s = a * h / 2
puts s, l, h
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 136,325
| 136,326
|
u717782380
|
ruby
|
p02380
|
#!/usr/bin/env ruby
a, b, c = gets.chomp.split.map(&:to_f)
c_rad = c * Math::PI / 180
l = Math.sqrt(a**2 + b**2 - a * b * Math.cos(c_rad)) + a + b
h = b * Math.sin(c_rad)
s = a * h / 2
puts s, l, h
|
#!/usr/bin/env ruby
a, b, c = gets.chomp.split.map(&:to_f)
c_rad = c * Math::PI / 180
l = Math.sqrt(a**2 + b**2 - 2 * a * b * Math.cos(c_rad)) + a + b
h = b * Math.sin(c_rad)
s = a * h / 2
puts s, l, h
|
[
"assignment.change"
] | 136,327
| 136,326
|
u717782380
|
ruby
|
p02380
|
a, b, c_theta = gets.split.map(&:to_i)
# surface
s = a * b * Math.sin(c_theta / 180.0 * Math::PI) / 2.0
puts s
# length in the circle
c = (a ** 2 + b ** 2 - 2 * a * b * Math.cos(c_theta / 180.0 * Math::PI)) ** (1/2.0)
puts a + b + c
# height h
h = b / Math.sin(c_theta / 180.0 * Math::PI)
puts h
|
a, b, c_theta = gets.split.map(&:to_i)
# surface
s = a * b * Math.sin(c_theta / 180.0 * Math::PI) / 2.0
puts s
# length in the circle
c = (a ** 2 + b ** 2 - 2 * a * b * Math.cos(c_theta / 180.0 * Math::PI)) ** (1/2.0)
puts a + b + c
# height h
h = b * Math.sin(c_theta / 180.0 * Math::PI)
puts h
|
[
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 136,328
| 136,329
|
u401720175
|
ruby
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.