Skip to content

Instantly share code, notes, and snippets.

@physacco
Last active December 17, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save physacco/afecfaea902512677e2b to your computer and use it in GitHub Desktop.
Save physacco/afecfaea902512677e2b to your computer and use it in GitHub Desktop.
My solutions to paiza POH 7
x=1;1.upto(gets.to_i){|i|x*=i};p x
def get_matrix(n):
return tuple(tuple(map(int, raw_input().strip().split())) for i in range(n))
def sub(nn, y, x, m):
return tuple(r[x:x+m] for r in nn[y:y+m])
def search(n, nn, m, mm):
e = n - m + 1
for y in range(e):
for x in range(e):
box = sub(nn, y, x, m)
if box == mm:
return (y, x)
n = int(raw_input())
nn = get_matrix(n)
m = int(raw_input())
mm = get_matrix(m)
print '%d %d' % search(n, nn, m, mm)
x,y,z,n=gets.strip.split.map(&:to_i)
k1=[0,x];k2=[0,y]
n.times{d,a=gets.strip.split.map(&:to_i);(d==0)?(k1<<a):(k2<<a)}
k1.sort!;k1d=1.upto(k1.size-1).map{|i| k1[i]-k1[i-1]}
k2.sort!;k2d=1.upto(k2.size-1).map{|i| k2[i]-k2[i-1]}
puts k1d.min*k2d.min*z
# rebase_n(144, 2) = (9, 4)
# i.e. 144 = 9 * (2 ** 4)
def rebase_n(x, n):
c = 0
while x % n == 0:
c += 1
x /= n
return (x, c)
# x = c * (5 ** b) * (2 ** a)
def rebase_5_2(x):
m, a = rebase_n(x, 2)
c, b = rebase_n(m, 5)
return (c, b, a)
def calc(n, k):
mod = 10 ** k
acc = [1, 0, 0]
for i in range(1, n + 1):
c, b, a = rebase_5_2(i)
acc[0] = (acc[0] * c) % mod
acc[1] += b
acc[2] += a
for i in range(acc[2] - acc[1]):
acc[0] = (acc[0] * 2) % mod
return acc[0]
def iter(n):
for i in range(1, n+1):
res = calc(i, 9)
print "%s: %s" % (i, res)
n = long(raw_input())
print calc(n, 9)
require 'set'
n=gets.to_i;m1=gets.to_i;s1=gets.strip.split.map(&:to_i).to_set;m2=gets.to_i;s2=gets.strip.split.map(&:to_i).to_set
s3=s2-s1;puts (s3.size==0)?'None':s3.to_a.sort.join(' ')
n=gets.to_i;m=gets.to_i;r=(m%n==0)?(m/n):(m/n+1);puts 1.upto(r).map{|i|(i%2==1)?'R':'W'}.map{|e|e*n}.join[0...m]
gets.to_i.times{print "Ann"}
puts gets.to_i+gets.to_i
a=b=0;5.times{gets[0]=='n'?(b+=1):(a+=1)};puts (a>b)?'yes':'no'
gets.to_i.downto(0){|i|puts "#{i}#{'!!' if i==0}"}
a,b,c,d=(gets+gets).split(/\s+/).map(&:to_f);puts (a/b>c/d)?1:2
puts gets.to_i.times.map{gets.strip}.join('_')

paiza POH 7 problems

恋愛SLG: プログラミングで彼女をつくる|paizaオンラインハッカソン7

ando2: つり目

输入1个整数n,要求在1行内把 "Ann" 输出n遍,中间无间隔

ando4: ショートヘア

输入2个整数a和b,输出(a+b)的值

ando5: ロングヘア

输入5个投票结果(yes/no),输出其中较多的一种

ando6: ポニーテール

输入1个数字n,输出从n到0的所有整数,每行1个,最后一行0的后面要加上"!!"

ando7: ツインテール

输入2种饮料的咖啡因含量和价格,输出性价比较高的一种

ando9: セーラー服

输入n个字符串,用下划线将它们依次连接起来并输出

ando10: カーディガン

输入1个整数n,输出它的阶乘

ando11: めがね

输入一大一小2个矩阵,已知小矩阵是大矩阵的一部分,要求输出小矩阵在大矩阵中的位置,用左上角坐标表示

ando12: サンタ服

输入一块方形蛋糕的长宽高,以及横向和纵向各切几刀、每一刀的位置,要求输出切出来的最小一块的体积

ando13: 水着

输入一个整数N,要求输出N的阶乘去掉末尾的所有0之后的最后9位数字,这9位数字前面的0也要去掉

ando16: 眼帯

输入已经持有的书籍编号和二手书店在售的书籍编号,要求输出应该购买的书籍编号,其实就是求2个集合的差集。

ando17: 縞ニーソ

已经红白相间的条纹的最大长度为m,单个条纹的长度为n,且条纹从红色开始,要求输出每个单位长度区间的颜色

==> ando2.1.in <==
3
==> ando2.1.out <==
AnnAnnAnn
==> ando2.2.in <==
10
==> ando2.2.out <==
AnnAnnAnnAnnAnnAnnAnnAnnAnnAnn
==> ando4.1.in <==
9
23
==> ando4.1.out <==
32
==> ando4.2.in <==
99
100
==> ando4.2.out <==
199
==> ando5.1.in <==
yes
yes
no
yes
no
==> ando5.1.out <==
yes
==> ando5.2.in <==
no
yes
no
no
yes
==> ando5.2.out <==
no
==> ando6.1.in <==
5
==> ando6.1.out <==
5
4
3
2
1
0!!
==> ando6.2.in <==
10
==> ando6.2.out <==
10
9
8
7
6
5
4
3
2
1
0!!
==> ando7.1.in <==
200 250
180 200
==> ando7.1.out <==
2
==> ando7.2.in <==
250 200
120 150
==> ando7.2.out <==
1
==> ando9.1.in <==
3
paiza
online
hackathon
==> ando9.1.out <==
paiza_online_hackathon
==> ando9.2.in <==
2
is
Android
==> ando9.2.out <==
is_Android
==> ando10.1.in <==
4
==> ando10.1.out <==
24
==> ando10.2.in <==
3
==> ando10.2.out <==
6
==> ando11.1.in <==
4
0 0 1 0
0 1 1 0
0 1 0 1
1 1 1 0
3
0 1 1
0 1 0
1 1 1
==> ando11.1.out <==
1 0
==> ando11.2.in <==
4
0 0 0 0
0 0 1 1
0 0 1 1
0 0 0 0
2
1 1
1 1
==> ando11.2.out <==
1 2
==> ando12.1.in <==
10 10 10 2
0 3
0 8
==> ando12.1.out <==
200
==> ando12.2.in <==
20 40 10 5
1 34
1 17
0 7
1 6
0 11
==> ando12.2.out <==
240
==> ando13.1.in <==
15
==> ando13.1.out <==
307674368
==> ando13.2.in <==
10
==> ando13.2.out <==
36288
==> ando16.1.in <==
5
3
1 3 4
3
2 3 5
==> ando16.1.out <==
2 5
==> ando16.2.in <==
8
5
1 3 4 5 6
3
1 5 6
==> ando16.2.out <==
None
==> ando17.1.in <==
3
10
==> ando17.1.out <==
RRRWWWRRRW
==> ando17.2.in <==
5
4
==> ando17.2.out <==
RRRR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment