{"id":4048,"date":"2018-12-09T15:39:25","date_gmt":"2018-12-09T12:39:25","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4048"},"modified":"2018-12-25T20:17:13","modified_gmt":"2018-12-25T17:17:13","slug":"e-olymp-2667-%d0%b7%d0%bc%d0%b5%d0%b9%d0%ba%d0%b0","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4048","title":{"rendered":"e-olymp 2667. \u0417\u043c\u0435\u0439\u043a\u0430"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 $x$ \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 $y$ \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0430 $n \\times m$, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0437\u043c\u0435\u0439\u043a\u043e\u0439: <img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/java.mazurok.com\/wp-content\/uploads\/2667-300x208.gif\" alt=\"\" width=\"300\" height=\"208\" class=\"aligncenter size-medium wp-image-4049\" \/><\/p>\n<h1>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0414\u0430\u043d\u044b \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 $n$, $m$, $x$, $y$ $ \\left ( 1 \\leq x \\leq n \\leq 50, 1 \\leq  y \\leq  m \\leq  50 \\right )$. \u0417\u0434\u0435\u0441\u044c $n$ &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043c\u0430\u0442\u0440\u0438\u0446\u044b, $m$ &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, $x$ \u0438 $y$ &#8212; \u043d\u043e\u043c\u0435\u0440\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0438\u0441\u043a\u043e\u043c\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<h1>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h1>\n<p>\u0412\u044b\u0432\u0435\u0441\u0442\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 $x$ \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 $y.$<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<table>\n<tbody>\n<tr>\n<td><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<td><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/strong><\/td>\n<\/tr>\n<tr>\n<td>$5 \\ 2 \\ 3 \\ 1$<\/td>\n<td>$4$<\/td>\n<\/tr>\n<tr>\n<td>$6 \\ 3 \\ 4 \\ 3$<\/td>\n<td>$9$<\/td>\n<\/tr>\n<tr>\n<td>$10 \\ 5 \\ 10 \\ 2$<\/td>\n<td>$48$<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h1>\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 n = in.nextInt();\r\n\t\tint m = in.nextInt();\r\n\t\tint x = in.nextInt();\r\n\t\tint y = in.nextInt();\r\n\t\tint[][] arr = new int [n][m];\r\n\t\tint num = 0;\r\n\t\tfor(int i = 0; i &lt; n; ++i) {\r\n\t\t\tint dir, j;\r\n\t\t\tif(i % 2 == 0){\r\n\t\t\t\tj = 0;\r\n\t\t\t\tdir = 1;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tj = m - 1;\r\n\t\t\t\tdir = -1;\r\n\t\t\t}\r\n\t\t\tfor(; j &lt; m &amp;&amp; j &gt;= 0; j += dir) {\r\n\t\t\t\tarr[i][j] = num;\r\n\t\t\t\t++num;\r\n\t\t\t}\r\n\t\t}\r\n\t\tSystem.out.print(arr[x - 1][y - 1]);\r\n\t}\r\n}<\/pre>\n<h1>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h1>\n<p>\u0427\u0438\u0442\u0430\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 $n$ \u043d\u0430 $m$, $num = 0$ \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u044d\u0442\u043e\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u0434\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0432 \u0446\u0438\u043a\u043b\u0435. \u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0441\u0442\u044c \u0447\u0438\u0441\u043b\u043e $j$ \u2014 \u043d\u043e\u043c\u0435\u0440 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 (\u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435), \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u0438 \u0447\u0438\u0441\u043b\u043e $dir$ \u2014 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u044d\u0442\u0438 \u0447\u0438\u0441\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c (\u043e\u043d\u043e \u0443 \u043d\u0430\u0441 1 \u0438\u043b\u0438 -1). \u0415\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0447\u0435\u0442\u043d\u0430\u044f, \u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0432\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435\u0447\u0435\u0442\u043d\u0430\u044f, \u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0430 \u043d\u0430\u043b\u0435\u0432\u043e. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u043c\u0443 \u0441\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440. \u0412 \u043e\u0442\u0432\u0435\u0442\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<h1>\u0421\u0441\u044b\u043b\u043a\u0438<\/h1>\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\/2667\" rel=\"noopener\" target=\"_blank\">e-olymp<\/a><\/p>\n<p>\u041a\u043e\u0434 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 <a href=\"https:\/\/ideone.com\/6XbZx3\" rel=\"noopener\" target=\"_blank\">ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 $x$ \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430 $y$ \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0440\u0430\u0437\u043c\u0435\u0440\u0430 $n \\times m$, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0437\u043c\u0435\u0439\u043a\u043e\u0439: \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0414\u0430\u043d\u044b \u043d\u0430\u0442\u0443\u0440\u0430\u043b\u044c\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 $n$, $m$, $x$, $y$ $ \\left ( 1 \\leq x \\leq n \\leq 50, 1 \\leq y \\leq m \\leq 50 \\right )$. \u0417\u0434\u0435\u0441\u044c $n$ &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043c\u0430\u0442\u0440\u0438\u0446\u044b, $m$ &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4048\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":124,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,26],"tags":[512,112,513],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4048"}],"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\/124"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4048"}],"version-history":[{"count":2,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4048\/revisions"}],"predecessor-version":[{"id":4051,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4048\/revisions\/4051"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}