1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paiza POH code_and_sql #異世界転職エンジニア

Last updated at Posted at 2022-08-22

SQL

同じデータベースを使う(取得する条件だけが徐々に複雑になっていく)のが面白く感じました。

魔法使いの街(d1)

SELECT id, name FROM Hell;

果ての平原(d2)

SELECT id, name, str FROM Hell ORDER BY str DESC LIMIT 5;

砂漠のオアシス(c1)

SELECT id, name, cost FROM Hell WHERE cost <= 10;

禁断の洞窟(c2)

SELECT Hell.id, Hell.name, Element.name AS element FROM Hell
  INNER JOIN Element ON Hell.element_id = Element.id
  WHERE Element.name = "Earth";

精霊の村(b1)

SELECT Hell.id, Hell.name, Element.name AS element, Grade.name AS grade FROM Hell
  INNER JOIN Element ON Hell.element_id = Element.id
  INNER JOIN Grade ON Hell.grade_id = Grade.id
  WHERE Element.name = "Air" AND Grade.name = "Boss";

獣の足跡(a1)

SELECT Hell.id, Hell.name, Element.name AS element, Grade.name AS grade FROM Hell
  INNER JOIN Element ON Hell.element_id = Element.id
  INNER JOIN Grade ON Hell.grade_id = Grade.id
  WHERE Grade.name = "Boss" AND Element.id in (
    SELECT ElementCompatibility.weakness_element_id FROM Hell
      INNER JOIN Element ON Hell.element_id = Element.id
      INNER JOIN ElementCompatibility ON Element.id = ElementCompatibility.element_id
      WHERE Hell.name = "Graffiacane"
  );

CODE

原初の村(d1)

#!/usr/bin/ruby
puts'hello'*gets.to_i

氷の城(d2)

#!/usr/bin/ruby
n=gets.to_i
puts n>0 ? n : :freeze

火山島(c1)

#!/usr/bin/ruby
SIZES=%w(SS S M L LL)
n=gets.to_i
v=gets.split.map &:to_i
v.unshift v[0]/2
v.push v[-1]*2
r=0
n.times{r+=v[SIZES.index gets.chomp]}
p r

大海の渦(b1)

#!/usr/bin/ruby
n,x,*d=`dd`.split.map &:to_i
d<< 0
r=[x]
(n-1).times{|i|
	d[i]-=r[-1]
	d[i+1]-=r[-1]
	r<< d[i]
}
puts r*' '

龍の頭(a1)

島ごとにその島を囲む矩形を算出し、その矩形と島の形が一致していれば良い。

#!/usr/bin/ruby
h,w=gets.split.map &:to_i
m=['W'*(w+2)]+h.times.map{'W'+gets.chomp+'W'}+['W'*(w+2)]
r=0
(1..h).each{|y0|(1..w).each{|x0|
	if m[y0][x0]=='B'
		q=[[y0,x0]]
		v=[[y0,x0]]
		m[y0][x0]='G'
		while !q.empty?
			y, x = q.shift
			[[-1, 0], [1, 0], [0, -1], [0, 1]].each{|dy,dx|
				ny = y + dy
				nx = x + dx
				if m[ny][nx]=='B'
					q<<[ny,nx]
					v<<[ny,nx]
					m[ny][nx]='G'
				end
			}
		end
		ym, yM = v.map(&:first).minmax
		xm, xM = v.map(&:last).minmax
		next if (ym..yM).any?{|y_|(xm..xM).any?{|x_|
			m[y_][x_]=='W'
		}}
		r+=1
	end
}}
p r

暗黒の地(s1)

だめですねこりゃ^^;;;
(杭の順番を変更できるならソートするだけで交差を減らすことが普通にできる)

#!/usr/bin/ruby
n,k=gets.split.map &:to_i
v=(1..n).map{|i|gets.split.map(&:to_i)+[i]}
p 0
# 既存の杭の順番は変更できないのか〜
puts *1..n
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?