Giter Club home page Giter Club logo

ios_algorithm_test's Introduction

Yêu cầu

Challenge

Giải thuật

Sử dụng thuật toán tìm kiếm theo chiều rộng BFS (Breadth-first search) trên một bàn cờ vua kích thước MxN với k ô cờ cản trở, tìm đường đi ngắn nhất từ ô A đến ô B, với mỗi bước di chuyển chỉ được phép đi đến ô kề cạnh và không được đi qua ô cản trở.

  1. Khởi tạo hàng đợi, thêm ô A vào hàng đợi và đánh dấu ô A là đã ghé thăm.
  2. Lặp lại các bước sau cho đến khi hàng đợi trống hoặc tìm được ô B:
  • Lấy ô đầu tiên ra khỏi hàng đợi và thêm nó vào danh sách đã duyệt.
  • Nếu ô này là ô B, dừng thuật toán và trả về số bước đi để đến được ô B.
  • Duyệt các ô kề cạnh của ô này (tức là các ô ở bên phải, bên trái, phía trên và phía dưới).
  • Nếu ô kề chưa được ghé thăm và không phải là ô cản trở, thêm ô này vào hàng đợi và đánh dấu nó là đã ghé thăm, đồng thời cập nhật số bước đi để đến được ô này.
  1. Nếu không tìm được đường đi từ ô A đến ô B, trả về giá trị -1.

Challenge

Kết quả

Nhập thử giá trị theo ví dụ result

Cách sử dụng

  • Clone repo này

https://github.com/QueenieeQ/Ios_Algorithm_Test.git

  • Mở Workspace

TimDuongDiNganNhat.xcworkspace

  • Thay đổi các tham số và in ra kết quả

Tham khảo

https://www.programiz.com/dsa/graph-bfs

https://vnoi.info/wiki/algo/graph-theory/breadth-first-search.md

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.