Created
September 23, 2015 07:22
-
-
Save oNguyenNgocTrung/af83169502e106c2c091 to your computer and use it in GitHub Desktop.
Question 1
This file contains hidden or 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
- Ý tưởng của em là khởi tạo mảng mới chứa các điểm X. Sau đó duyệt qua từng hàng. | |
so sánh hoành độ của các điểm X của hàng đang duyệt với các điểm trong mảng các ao. | |
Nếu chênh nhau 1 thì nạp thêm điểm mới vào ao kia. | |
ví dụ như bài trên: | |
Ta có mảng arr_land chứa tất cả các ao | |
- Duyệt Row 1 : có Ao1 = {(0,0)}, Ao2 = {(0,9), (0,10)} --> add Ao1, Ao2 vào mảng arr_land | |
- Duyệt Row 2: có Ao3 = {(1,1),{1,2),(1,3)}, Ao4 = {(1,9),(1,10),(1,11)} | |
Xet Ao3 có phần tử (1,1) có chung đỉnh vs đỉnh (0,0) của Ao1 nên gộp 2 mảng Ao1 và Ao3 lại--> tượng tư vs Ao4 | |
vậy ta vẫn có magr arr_land chứa 2 ao Ao1 {(0,0),(1,1),{1,2),(1,3)} và Ao2 {(0,9), (0,10), (1,9),(1,10),(1,11) } | |
Sau đó xét tiếp tục với các dòng tiếp theo. |
This file contains hidden or 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
puts "row = ?" | |
row = gets.chomp.to_i | |
puts "col = ?" | |
col = gets.chomp.to_i | |
arr_land = [] | |
arr = [] | |
(1..row).each do |i| | |
puts "row #{i}: " | |
arr >> gets.chomp.split(" ") | |
end | |
print "\n\n\n" | |
puts "---------------My Land---------------" | |
puts "#{row} #{col}" | |
(1..row).each do |i| | |
(1..col).each do |j| | |
print "#{arr[i-1][j-1]} " | |
if arr[i-1][j-1] == "X" | |
arr_land << [arr[i-1][j-1]] | |
end | |
end | |
print "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment