{"id":4448,"date":"2018-12-26T10:34:00","date_gmt":"2018-12-26T07:34:00","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4448"},"modified":"2018-12-27T18:05:25","modified_gmt":"2018-12-27T15:05:25","slug":"e-olymp-4557-%d0%be%d0%b4%d0%b8%d0%bd%d0%be%d0%ba%d0%b8%d0%b9-%d0%ba%d0%be%d1%80%d0%be%d0%bb%d1%8c","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4448","title":{"rendered":"e-olymp 4557. \u041e\u0434\u0438\u043d\u043e\u043a\u0438\u0439 \u043a\u043e\u0440\u043e\u043b\u044c"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/java.mazurok.com\/wp-content\/uploads\/1picture.jpg\" alt=\"\u041f\u043e\u0437\u0438\u0446\u0438\u044f \u043a\u043e\u0440\u043e\u043b\u044f \u043d\u0430 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435\" width=\"238\" height=\"235\" class=\"size-full wp-image-4484\" \/><\/p>\n<p>\u041e\u0434\u0438\u043d\u043e\u043a\u0438\u0439 \u043a\u043e\u0440\u043e\u043b\u044c \u0434\u043e\u043b\u0433\u043e \u0431\u0440\u043e\u0434\u0438\u043b \u043f\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 $n$ \u0435\u0433\u043e \u0445\u043e\u0434\u043e\u0432 (\u0432\u0432\u0435\u0440\u0445, \u0432\u043d\u0438\u0437, \u0432\u043b\u0435\u0432\u043e, \u0432\u043f\u0440\u0430\u0432\u043e, \u0432\u0432\u0435\u0440\u0445-\u0432\u043b\u0435\u0432\u043e \u0438 \u0442.\u043f.) \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0445\u043e\u0434\u044b \u043a\u043e\u0440\u043e\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0441\u043d\u0438\u0437\u0443.<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u043f\u043e\u0431\u044b\u0432\u0430\u043b \u043b\u0438 \u043a\u043e\u0440\u043e\u043b\u044c \u0434\u0432\u0430\u0436\u0434\u044b \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u043b\u0435 \u0437\u0430 \u0441\u0432\u043e\u0438 $n$ \u0445\u043e\u0434\u043e\u0432.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/java.mazurok.com\/wp-content\/uploads\/2picture.jpg\" alt=\"\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0445\u043e\u0434\u044b \u043a\u043e\u0440\u043e\u043b\u044f\" width=\"243\" height=\"244\" class=\"size-full wp-image-4485\" srcset=\"https:\/\/java.mazurok.com\/wp-content\/uploads\/2picture.jpg 243w, https:\/\/java.mazurok.com\/wp-content\/uploads\/2picture-150x150.jpg 150w\" sizes=\"(max-width: 243px) 100vw, 243px\" \/><\/p>\n<h2>\u0412\u0432\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0445\u043e\u0434\u043e\u0432 \u043a\u043e\u0440\u043e\u043b\u044f $n$ $(0 \\leq n \\leq 1000)$. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 $n$ \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u043e\u043b\u044f: \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c $i+1$ \u0437\u0430\u0434\u0430\u0451\u0442 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043a\u043e\u0440\u043e\u043b\u044f \u043d\u0430 $i$-\u043e\u043c \u0445\u043e\u0434\u0443.<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0412\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u2014 \u043d\u043e\u043c\u0435\u0440 \u0445\u043e\u0434\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043e\u0440\u043e\u043b\u044c \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u043e\u043f\u0430\u043b \u043d\u0430 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u043a\u043b\u0435\u0442\u043a\u0443 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0437. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u0435\u0434\u0438\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 <strong>\u00abOk\u00bb<\/strong> (\u0431\u0435\u0437 \u043a\u0430\u0432\u044b\u0447\u0435\u043a), \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 \u043c\u0430\u043d\u0445\u044d\u0442\u0442\u0435\u043d\u0441\u043a\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043f\u0443\u0442\u0435\u0448\u0435\u0441\u0442\u0432\u0438\u044f \u043e\u0434\u0438\u043d\u043e\u043a\u043e\u0433\u043e \u043a\u043e\u0440\u043e\u043b\u044f.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043c\u0430\u043d\u0445\u044d\u0442\u0442\u0435\u043d\u0441\u043a\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 $(x_1, y_1)$ \u0438 $(x_2, y_2)$ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435: $d=|x_2 &#8212; x_1| + |y_2 &#8212; y_1|$.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u044b<\/h2>\n<table>\n<tr>\n<td>\n\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n<\/td>\n<td>\n\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n<\/td>\n<\/tr>\n<tr>\n<td>\n$5\\;1\\;2\\;4\\;7\\;4$\n<\/td>\n<td>\n$4$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$5\\;1\\;2\\;4\\;6\\;4$\n<\/td>\n<td>\n$Ok$<br \/>\n$2$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$8\\;3\\;3\\;7\\;7\\;5\\;5\\;3\\;3$\n<\/td>\n<td>\n$3$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$12\\;2\\;3\\;4\\;1\\;3\\;2\\;5\\;6\\;8\\;2\\;1\\;7$\n<\/td>\n<td>\n$10$\n<\/td>\n<\/tr>\n<tr>\n<td>\n$9\\;2\\;2\\;3\\;3\\;4\\;4\\;7\\;7\\;7$\n<\/td>\n<td>\n$Ok$<br \/>\n2\n<\/td>\n<\/tr>\n<\/table>\n<h2>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h2>\n<pre class=\"lang:java decode:true \">import java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Main\r\n{\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tScanner in = new Scanner(System.in);\r\n\t\tint[][] x = new int[2001][2001];\r\n\t\tint n = in.nextInt();\r\n\t\tint move;\r\n\t\tint xPos=1001, yPos=1001;\r\n\t\tfor(int i = 0; i &lt; n; i++) {\r\n\t\t\tmove = in.nextInt();\r\n\t\t\tif(x[xPos][yPos] == 1) { \r\n            \tSystem.out.print(i);\r\n            \treturn;\r\n        \t}\r\n        \telse x[xPos][yPos]=1;\r\n\t        if(move == 1) {\r\n\t            xPos--;\r\n\t            yPos++;\r\n\t        }\r\n\t        if(move == 2) {\r\n\t            yPos++;\r\n\t        }\r\n\t        if(move == 3) {\r\n\t            xPos++;\r\n\t            yPos++;\r\n\t        }\r\n\t        if(move == 4) {\r\n\t            xPos++;\r\n\t        }\r\n\t        if(move == 5) {\r\n\t            xPos++;\r\n\t            yPos--;\r\n\t        }\r\n\t        if(move == 6) {\r\n\t            yPos--;\r\n\t        }\r\n\t        if(move == 7) {\r\n\t            xPos--;\r\n\t            yPos--;\r\n\t        }\r\n\t        if(move == 8) {\r\n\t            xPos--;\r\n\t        }\r\n\t\t}\r\n\t\tSystem.out.print(\"Ok\" + \"\\n\" + (Math.abs(xPos-1001)+Math.abs(yPos-1001)));\r\n\t}\r\n}\r\n<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432(\u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u043d\u0443\u043b\u044f\u043c\u0438). \u0417\u0430\u0434\u0430\u0435\u043c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043a\u043e\u0440\u043e\u043b\u044f \u043f\u043e \u0446\u0435\u043d\u0442\u0440\u0443 <code>int xPos=1001, yPos=1001;<\/code>. \u0417\u0430\u0442\u0435\u043c \u0432 \u0446\u0438\u043a\u043b\u0435 \u0432\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0445\u043e\u0434\u044b \u043a\u043e\u0440\u043e\u043b\u044f \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0431\u044b\u043b \u043b\u0438 \u043e\u043d \u0443\u0436\u0435 \u0432 \u044d\u0442\u043e\u0439 \u044f\u0447\u0435\u0439\u043a\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0441\u0442\u0430\u0432\u0438\u043c $1$, \u0438 \u0432\u0432\u043e\u0434\u0438\u043c \u0445\u043e\u0434 \u043a\u043e\u0440\u043e\u043b\u044f \u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u0435\u043c\u0443 \u043d\u043e\u0432\u044b\u0435 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b, \u0435\u0441\u043b\u0438 \u0434\u0430 \u2014 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u043d\u043e\u043c\u0435\u0440 \u0445\u043e\u0434\u0430 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0415\u0441\u043b\u0438 \u043a\u043e\u0440\u043e\u043b\u044c \u043d\u0438 \u0440\u0430\u0437\u0443 \u043d\u0435 \u043f\u043e\u043f\u0430\u043b \u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0443\u0436\u0435 \u0431\u044b\u043b, \u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043c\u0430\u043d\u0445\u044d\u0442\u0442\u0435\u043d\u0441\u043a\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438. \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>\u0423\u0441\u043b\u043e\u0432\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/4557\">e-olymp<\/a><br \/>\n\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 <a href=\"https:\/\/ideone.com\/mIPdUa\">ideone.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041e\u0434\u0438\u043d\u043e\u043a\u0438\u0439 \u043a\u043e\u0440\u043e\u043b\u044c \u0434\u043e\u043b\u0433\u043e \u0431\u0440\u043e\u0434\u0438\u043b \u043f\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0448\u0430\u0445\u043c\u0430\u0442\u043d\u043e\u0439 \u0434\u043e\u0441\u043a\u0435. \u0418\u0437\u0432\u0435\u0441\u0442\u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 $n$ \u0435\u0433\u043e \u0445\u043e\u0434\u043e\u0432 (\u0432\u0432\u0435\u0440\u0445, \u0432\u043d\u0438\u0437, \u0432\u043b\u0435\u0432\u043e, \u0432\u043f\u0440\u0430\u0432\u043e, \u0432\u0432\u0435\u0440\u0445-\u0432\u043b\u0435\u0432\u043e \u0438 \u0442.\u043f.) \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0445\u043e\u0434\u044b \u043a\u043e\u0440\u043e\u043b\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0441\u043d\u0438\u0437\u0443. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u0435, \u043f\u043e\u0431\u044b\u0432\u0430\u043b \u043b\u0438 \u043a\u043e\u0440\u043e\u043b\u044c \u0434\u0432\u0430\u0436\u0434\u044b \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438 \u0442\u043e\u043c \u0436\u0435 \u043f\u043e\u043b\u0435 \u0437\u0430 \u0441\u0432\u043e\u0438 $n$ \u0445\u043e\u0434\u043e\u0432. \u0412\u0432\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u0434\u0430\u043d\u043e \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0445\u043e\u0434\u043e\u0432 \u043a\u043e\u0440\u043e\u043b\u044f &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4448\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":132,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[613,612,611],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4448"}],"collection":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/users\/132"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4448"}],"version-history":[{"count":19,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4448\/revisions"}],"predecessor-version":[{"id":4504,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4448\/revisions\/4504"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}