Skip to content

Commit

Permalink
Add Files
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeaning777 committed Dec 6, 2011
1 parent d319565 commit b3e2510
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 3 deletions.
13 changes: 13 additions & 0 deletions 112B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=gets
s1="4"
r1=s.scan(s1).size
s2="7"
r2=s.scan(s2).size
if [r1,r2].max==0 then
puts "-1"
elsif r1>=r2 then
puts "4"
else
puts "7"
end

9 changes: 9 additions & 0 deletions 11B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
n=gets.to_i.abs
i=1
k=0
while k<n || (k-n)&1>0
k+=i
i+=1
end
#p k
puts i-1
6 changes: 6 additions & 0 deletions 122A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
n=gets.to_i
lucky=[4,7,44,47,74,77,444,447,474,477,744,747,777,4444,4447,4474,4477,4744,4747,4774,4777,7444,7447,7474,7477,7744,7747,7774,7777]
lucky.each{|i|
if n%i==0 then puts "YES";exit; end
}
puts "NO"
10 changes: 10 additions & 0 deletions 124A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
n,a,b=gets.split.map(&:to_i)
ans=0
for i in 1..n
if i-1>=a then
if n-i<=b then
ans+=1
end
end
end
p ans
28 changes: 28 additions & 0 deletions 124B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
n,k=gets.split.map(&:to_i);
p=[];input=[];
n.times{
s=gets.split[0]
tmp=[]
k.times{|i|
tmp.push(s[i].to_i)
}
input.push(tmp)
}
ans=[]
k.times{|i|
p.push(i);
}
p.permutation{|a|
t=[]
input.each{|i|
tmp=0
k.times{|j|
tmp*=10
tmp+=i[a[j]]
}
t.push(tmp)
}
ans.push(t.max-t.min)
}
p ans.min

1 change: 1 addition & 0 deletions 125A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts "#{(n=(gets.to_i/3.0+0.5).to_i)/12} #{n%12}"
14 changes: 14 additions & 0 deletions 125B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
str=gets
input=str[1..str.length-3].split("><")
depth=0
input.each{|a|
if a[0]=="/" then
depth-=1
print " "*depth
else
print " "*depth
depth+=1
end
print "<"+a+">\n"
}

10 changes: 10 additions & 0 deletions 127A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
n,k=gets.split.map(&:to_i)
point=[]
for i in 1..n
point.push(gets.split.map(&:to_i))
end
res=0.0
for i in 1..n-1
res+=Math::sqrt((point[i-1][0]-point[i][0])**2+(point[i-1][1]-point[i][1])**2)
end
p res/50*k
8 changes: 8 additions & 0 deletions 127B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n=gets.to_i
a=gets.split.map(&:to_i)
cnt=Hash.new
cnt.default=0
a.each{|i| cnt[i]+=1 }
ans=0
1.upto(100){|i| ans+=cnt[i]/2 }
p ans/2
11 changes: 11 additions & 0 deletions 129A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n=gets.to_i
a=gets.split.map(&:to_i)
o=e=0
a.each{|i|
if i % 2==0 then e+=1 else o+=1 end
}
if o % 2 == 0 then
puts e
else
puts o
end
8 changes: 8 additions & 0 deletions 131A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
str=gets.split[0]
if str.upcase==str then
puts str.downcase
elsif str[0].downcase+str[1..str.length-1].upcase==str then
puts str[0].upcase+str[1..str.length-1].downcase
else
puts str
end
12 changes: 12 additions & 0 deletions 131B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
n=gets
t=gets.split.map(&:to_i)
cnt=Hash.new
cnt.default=0
t.each{|i|
cnt[i]+=1
}
ans=cnt[0]*(cnt[0]-1)/2
for i in 1..10
ans+=cnt[i]*cnt[-i]
end
p ans
15 changes: 15 additions & 0 deletions 131C.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
n,m,t=gets.split.map(&:to_i)
def fact(i)
if i<=1 then return 1 end
return i*fact(i-1)
end
def comb(n,k)
return fact(n)/fact(k)/fact(n-k)
end
ans=0
for d in 4..n
j=t-d
if j==0 then next end
ans+=comb(n,d)*comb(m,j)
end
p ans
1 change: 1 addition & 0 deletions 133A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
puts /[HQ9]/ =~ gets.split[0] ? "YES" : "NO"
8 changes: 8 additions & 0 deletions 133B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hash={"+"=>"1010",">"=>"1000","<"=>"1001","-"=>"1011","."=>"1100",","=>"1101","["=>"1110","]"=>"1111"}
program=gets.split[0]
ans=""
0.upto(program.length-1){|i|
ans+=hash[program[i]]
}
p ans.to_i(2)%1000003

12 changes: 12 additions & 0 deletions 134A.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sum=gets.to_i*0
a=gets.split.map(&:to_i)
a.each{|s| sum+=s}
ans=[]
a.length.times{|i|
if a[i]*(a.length-1)==(sum-a[i])
ans.push(i)
end
}
p ans.length
ans.each{|i| print "#{i+1} "}
puts
25 changes: 25 additions & 0 deletions 134B.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def solve(n,k)
big=n;small=k
a=0
while big!=1||small!=1
t=big/small
if big%small==0 then t-=1 end
a+=t
big-=t*small
if big<small then
big,small=small,big
end
end
a
end
# 最後の数字を家庭する
n=gets.to_i
ans=99999999

for i in 1..(n+1)/2
if n.gcd(i)!=1 then next end
ans=[ans,solve(n,i)].min
#p [n,i,solve(n,i)]
end
p ans

1 change: 1 addition & 0 deletions 54A.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if t[0]==i then
back=i
ans+=1
t.shift
elsif i-back>=k then
back=i
ans+=1
Expand Down
10 changes: 7 additions & 3 deletions 8A.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
def solve(data)
if data.match( eval("/[a-z]*"+$a+"[a-z]*"+$b+"[a-z]*/") ) != nil then
return true
else
q=data.index($a)
if q==nil then
return false
end
r=data.rindex($b)
if r==nil then
return false
end
return q+$a.length<=r
end

input=gets.split[0]
Expand Down

0 comments on commit b3e2510

Please sign in to comment.