-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d319565
commit b3e2510
Showing
19 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts /[HQ9]/ =~ gets.split[0] ? "YES" : "NO" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
if t[0]==i then | ||
back=i | ||
ans+=1 | ||
t.shift | ||
elsif i-back>=k then | ||
back=i | ||
ans+=1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters