{"id":299734,"date":"2020-03-05T21:00:13","date_gmt":"2020-03-05T21:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=299734"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=299734","title":{"rendered":"\u0412\u044b\u043f\u0443\u0441\u043a#32: IT\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u2014 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442 \u0432\u0435\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/491016\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. \u041c\u044b \u0432\u043d\u043e\u0432\u044c \u0438 \u0432\u043d\u043e\u0432\u044c \u0440\u0430\u0434\u0443\u0435\u043c \u0412\u0430\u0441 \u043d\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0437\u0430\u0434\u0430\u0447\u0435\u043a \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0432\u0435\u0434\u0443\u0449\u0438\u0435 IT-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438!<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u043a\u0438 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430 \u0443\u0436\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/489302\/\">\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b<\/a>!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mm\/ts\/bf\/mmtsbfkkeyhk8ypc4kkn5qt33j8.png\"><\/p>\n<p>  \u0412\u044b\u043f\u0443\u0441\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u0443\u044e \u043d\u0435\u0434\u0435\u043b\u044e \u2014 \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438! \u0420\u0443\u0431\u0440\u0438\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0440\u0435\u043a\u0440\u0443\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u0430\u0433\u0435\u043d\u0442\u0441\u0442\u0432\u0430 <a href=\"http:\/\/www.spice-agency.ru\/ru\/\">Spice IT<\/a>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u043c\u044b \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0438\u043d\u0434\u0438\u0439\u0441\u043a\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e MakeMyTrip.<a name=\"habracut\"><\/a><\/p>\n<h2>\u0412\u043e\u043f\u0440\u043e\u0441\u044b<\/h2>\n<p>  1. <b>10 Coins Puzzle<\/b>  <\/p>\n<blockquote><p>You are blindfolded and 10 coins are place in front of you on table. You are allowed to touch the coins, but can\u2019t tell which way up they are by feel. You are told that there are 5 coins head up, and 5 coins tails up but not which ones are which.<\/p>\n<p>  Can you make two piles of coins each with the same number of heads up? You can flip the coins any number of times.<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u0412\u0430\u043c \u0437\u0430\u0432\u044f\u0437\u044b\u0432\u0430\u044e\u0442 \u0433\u043b\u0430\u0437\u0430 \u0438 \u043a\u043b\u0430\u0434\u0443\u0442 10 \u043c\u043e\u043d\u0435\u0442 \u043d\u0430 \u0441\u0442\u043e\u043b \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0442\u0440\u043e\u0433\u0430\u0442\u044c \u043c\u043e\u043d\u0435\u0442\u044b, \u043d\u043e \u043d\u0430 \u043e\u0449\u0443\u043f\u044c \u0432\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d \u0432\u0432\u0435\u0440\u0445 \u043b\u0435\u0436\u0430\u0442 \u043c\u043e\u043d\u0435\u0442\u044b. \u0412\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u044f\u0442, \u0447\u0442\u043e \u0435\u0441\u0442\u044c 5 \u043c\u043e\u043d\u0435\u0442, \u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u0430\u0432\u0435\u0440\u0441\u043e\u043c (\u00ab\u0440\u0435\u0448\u043a\u043e\u0439\u00bb) \u0432\u0432\u0435\u0440\u0445 \u0438 5 \u043c\u043e\u043d\u0435\u0442, \u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u0440\u0435\u0432\u0435\u0440\u0441\u043e\u043c (\u00ab\u043e\u0440\u043b\u043e\u043c\u00bb) \u0432\u0432\u0435\u0440\u0445, \u043d\u043e \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u2014 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043e. <\/p>\n<p>  \u041c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438 \u0432\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0432\u0435 \u043a\u0443\u0447\u043a\u0438 \u043c\u043e\u043d\u0435\u0442 \u0441 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043c\u043e\u043d\u0435\u0442, \u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u0430\u0432\u0435\u0440\u0441\u043e\u043c \u0432\u0432\u0435\u0440\u0445? \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043c\u043e\u043d\u0435\u0442\u044b \u043b\u044e\u0431\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437.<\/p><\/div>\n<\/div>\n<p>  2. <b>Newspaper Puzzle<\/b>  <\/p>\n<blockquote><p>A newspaper made of 16 large sheets of paper folded in half. The newspaper has 64 pages altogether. The first sheet contains pages 1, 2, 63, 64.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ke\/oe\/6c\/keoe6cz1q7lcmddulpjyy-in-h0.png\"><br \/>  If we pick up a sheet containing page number 45. What are the other pages that this sheet contains?<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u0413\u0430\u0437\u0435\u0442\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 16 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043b\u0438\u0441\u0442\u043e\u0432 \u0431\u0443\u043c\u0430\u0433\u0438, \u0441\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043f\u043e\u043b\u0430\u043c. \u0412\u0441\u0435\u0433\u043e \u0432 \u0433\u0430\u0437\u0435\u0442\u0435 64 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b. \u041f\u0435\u0440\u0432\u044b\u0439 \u043b\u0438\u0441\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b 1, 2, 63, 64.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ke\/oe\/6c\/keoe6cz1q7lcmddulpjyy-in-h0.png\"><br \/>  * \u0433\u0430\u0437\u0435\u0442\u0430 \u0441\u043b\u043e\u0436\u0435\u043d\u0430 \u043f\u043e\u043f\u043e\u043b\u0430\u043c<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043b\u0438\u0441\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b 45. \u041a\u0430\u043a\u0438\u0435 \u0435\u0449\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u044d\u0442\u043e\u0442 \u043b\u0438\u0441\u0442?<\/p><\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u0417\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>  1. <b>Transpose of Matrix<\/b>  <\/p>\n<blockquote><p>Write a program to find transpose of a square matrix <b>mat[][]<\/b> of size <b>N*N<\/b>. Transpose of a matrix is obtained by changing rows to columns and columns to rows.<\/p>\n<p>  <b>Input:<\/b><br \/>  The first line of input contains an integer <b>T<\/b>, denoting the number of testcases. Then <b>T<\/b> test cases follow. Each test case contains an integer <b>N<\/b>, denoting the size of the square matrix. Then in the next line are <b>N*N<\/b> space separated values of the matrix.<\/p>\n<p>  <b>Output:<\/b><br \/>  For each test case output will be the space separated values of the transpose of the matrix<\/p>\n<p>  <b>Constraints:<\/b><br \/>  <code>1 &lt;= T &lt;= 15<br \/>  1 &lt;= N &lt;= 20<br \/>  -103 &lt;= mat[i][j] &lt;= 103<\/code><\/p>\n<p>  <b>Example:<br \/>  Input:<\/b><br \/>  <code>2<br \/>  4<br \/>  1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4<br \/>  2<br \/>  1 2 -9 -2<\/code><\/p>\n<p>  <b>Output:<\/b><br \/>  <code>1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4<br \/>  1 -9 2 -2<\/code><\/p>\n<p>  <b>Explanation:<\/b><br \/>  <b>Testcase 1:<\/b> The matrix after rotation will be: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4.<\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b <b>mat[][]<\/b> \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <b>N*N<\/b>. \u0422\u0440\u0430\u043d\u0441\u043f\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u043e\u043a \u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <b>\u0412\u0432\u043e\u0434:<\/b><br \/>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <b>T<\/b>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432. \u0417\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0442 <b>T<\/b> \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <b>N<\/b>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b. \u0417\u0430\u0442\u0435\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f <b>N*N<\/b> \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b.<\/p>\n<p>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b><br \/>  \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b<\/p>\n<p>  <b>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/b><br \/>  <code>1 &lt; = T &lt;= 15<br \/>  1 &lt; = N &lt;= 20<br \/>  -103 &lt; = mat[i] [j] &lt; = 103<\/code><\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440:<br \/>  \u0412\u0432\u043e\u0434:<\/b><br \/>  <code>2<br \/>  4<br \/>  1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4<br \/>  2<br \/>  1 2 -9 -2<\/code><\/p>\n<p>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b><br \/>  <code>1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4<br \/>  1 -9 2 -2<\/code><\/p>\n<p>  <b>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/b><br \/>  \u0422\u0435\u0441\u0442 1: \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043f\u043e\u0441\u043b\u0435 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442: 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4.<\/div>\n<\/div>\n<p>  2. <b>Trailing zeroes in factorial<\/b>  <\/p>\n<blockquote><p>For an integer <b>n<\/b> find number of trailing zeroes in <b>n!<\/b>. <\/p>\n<p>  <b>Input:<\/b><br \/>  The first line contains an integer &#8216;<b>T<\/b>&#8216; denoting the total number of test cases. In each test cases, it contains an integer &#8216;<b>N<\/b>&#8216;.<\/p>\n<p>  <b>Output:<\/b><br \/>  In each seperate line output the answer to the problem.<\/p>\n<p>  <b>Constraints:<\/b><br \/>  <code>1 &lt;= T &lt;= 100<br \/>  1 &lt;= N &lt;= 1000<\/code><\/p>\n<p>  <b>Example:<br \/>  Input:<\/b><br \/>  <code>1<br \/>  9<\/code><br \/>  <b>Output:<\/b><br \/>  <code>1<\/code><\/p><\/blockquote>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u0414\u043b\u044f \u0446\u0435\u043b\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 <b>n<\/b> \u043d\u0430\u0439\u0434\u0438\u0442\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0443\u043b\u0435\u0439 \u043d\u0430 \u043a\u043e\u043d\u0446\u0435 \u0447\u0438\u0441\u043b\u0430 <b>n!<\/b>. <\/p>\n<p>  <b>\u0412\u0432\u043e\u0434: <\/b><br \/>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &#8216;<b>T<\/b>&#8216;, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0435\u0435 \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u0435\u0441\u0442\u043e\u0432. \u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0442\u0435\u0441\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &#8216;<b>N<\/b>&#8216;.<\/p>\n<p>  <b>\u0412\u044b\u0445\u043e\u0434: <\/b><br \/>  \u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>  <b>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/b> <br \/>  <code>1 &lt; = T &lt;= 100<br \/>  1 &lt; = N &lt; = 1000<\/code><\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440: <br \/>  \u0412\u0432\u043e\u0434: <\/b><br \/>  <code>1<br \/>  9<\/code><br \/>  <b>\u0412\u044b\u0445\u043e\u0434: <\/b><br \/>  <code>1<\/code><\/div>\n<\/div>\n<p>  3. <b>Steps by Knight<\/b>  <\/p>\n<blockquote><p>Given a square chessboard of <b>N x N<\/b> size, the position of Knight and position of a target is given. We need to find out minimum steps a Knight will take to reach the target position.<\/p>\n<p>  <b>Input:<\/b><br \/>  The first line of input contains an integer <b>T<\/b> denoting the number of test cases. Then <b>T<\/b> test cases follow. Each test case contains an integer n denoting the size of the square chessboard. The next line contains the <b>X-Y<\/b> coordinates of the knight. The next line contains the <b>X-Y<\/b> coordinates of the target. <\/p>\n<p>  <b>Output:<\/b><br \/>  Print the minimum steps the Knight will take to reach the target position.<\/p>\n<p>  <b>Constraints:<\/b><br \/>  <code>1&lt;=T&lt;=100<br \/>  1&lt;=N&lt;=20<br \/>  1&lt;=knight_pos,targer_pos&lt;=N<\/code><\/p>\n<p>  <b>Example:<br \/>  Input:<\/b><br \/>  <code>2<br \/>  6<br \/>  4 5<br \/>  1 1<br \/>  20<br \/>  5 7<br \/>  15 20<\/code><\/p>\n<p>  <b>Output:<\/b><br \/>  <code>3<br \/>  9<\/code><\/p><\/blockquote>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0435\u0440\u0435\u0432\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\u041d\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0439 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c <b>N x N<\/b> \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u044f \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u0438. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0448\u0430\u0433\u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u043a\u043e\u043d\u044c, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0446\u0435\u043b\u0438.<\/p>\n<p>  <b>\u0412\u0432\u043e\u0434:<\/b><br \/>  \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <b>T<\/b>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u0441\u0442\u043e\u0432. \u0417\u0430\u0442\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0442 <b>T<\/b> \u0442\u0435\u0441\u0442\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e <b>n<\/b>, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0435\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u043e\u0439 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0438. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b <b>X-Y<\/b> \u043a\u043e\u043d\u044f. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b <b>X-Y<\/b> \u0446\u0435\u043b\u0438.<\/p>\n<p>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b><br \/>  \u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0448\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043d\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<p>  <b>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f:<\/b><br \/>  <code>1&lt;=T&lt;=100<br \/>  1&lt;=N&lt;=20<br \/>  1&lt;=knight_pos,targer_pos&lt;=N<\/code><\/p>\n<p>  <b>\u041f\u0440\u0438\u043c\u0435\u0440:<br \/>  \u0412\u0432\u043e\u0434:<\/b><br \/>  <code>2<br \/>  6<br \/>  4 5<br \/>  1 1<br \/>  20<br \/>  5 7<br \/>  15 20<\/code><\/p>\n<p>  <b>\u0412\u044b\u0445\u043e\u0434:<\/b><br \/>  <code>3<br \/>  9<\/code><\/div>\n<\/div>\n<p>  \u041e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u043d\u044b \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043d\u0435\u0434\u0435\u043b\u0438 \u2014 \u0443\u0441\u043f\u0435\u0439\u0442\u0435 \u0440\u0435\u0448\u0438\u0442\u044c. \u0423\u0434\u0430\u0447\u0438!<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/491016\/\"> https:\/\/habr.com\/ru\/company\/spice\/blog\/491016\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/491016\/\">\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. \u041c\u044b \u0432\u043d\u043e\u0432\u044c \u0438 \u0432\u043d\u043e\u0432\u044c \u0440\u0430\u0434\u0443\u0435\u043c \u0412\u0430\u0441 \u043d\u043e\u0432\u043e\u0439 \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u0437\u0430\u0434\u0430\u0447\u0435\u043a \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0432\u0435\u0434\u0443\u0449\u0438\u0435 IT-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438!<\/p>\n<p>  \u041a\u0441\u0442\u0430\u0442\u0438, \u043e\u0442\u0432\u0435\u0442\u044b \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u043a\u0438 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430 \u0443\u0436\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/spice\/blog\/489302\/\">\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u044b<\/a>!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/mm\/ts\/bf\/mmtsbfkkeyhk8ypc4kkn5qt33j8.png\"><\/p>\n<p>  \u0412\u044b\u043f\u0443\u0441\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u0443\u044e \u043d\u0435\u0434\u0435\u043b\u044e \u2014 \u0441\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438! \u0420\u0443\u0431\u0440\u0438\u043a\u0430 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0440\u0435\u043a\u0440\u0443\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0433\u043e \u0430\u0433\u0435\u043d\u0442\u0441\u0442\u0432\u0430 <a href=\"http:\/\/www.spice-agency.ru\/ru\/\">Spice IT<\/a>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0435 \u043c\u044b \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0439 \u0432 \u0438\u043d\u0434\u0438\u0439\u0441\u043a\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e MakeMyTrip.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-299734","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=299734"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/299734\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=299734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=299734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=299734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}