{"id":4791,"date":"2018-12-28T12:34:10","date_gmt":"2018-12-28T09:34:10","guid":{"rendered":"http:\/\/java.mazurok.com\/?p=4791"},"modified":"2019-01-03T19:48:02","modified_gmt":"2019-01-03T16:48:02","slug":"e-olymp-2671-%d1%81%d0%b0%d0%bf%d0%b5%d1%80","status":"publish","type":"post","link":"https:\/\/java.mazurok.com\/?p=4791","title":{"rendered":"e-olymp 2671. \u0421\u0430\u043f\u0435\u0440"},"content":{"rendered":"<h1>\u0417\u0430\u0434\u0430\u0447\u0430<\/h1>\n<p>\u0414\u0430\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0438\u043d. \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0438\u0433\u0440\u044b \u0432 \u0441\u0430\u043f\u0435\u0440.<\/p>\n<h2>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0414\u0430\u043d\u044b \u0447\u0438\u0441\u043b\u0430 $N$ \u0438 $M$ (\u0446\u0435\u043b\u044b\u0435, \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435, \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0442 $32$) &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043f\u043e\u043b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u0430\u043b\u0435\u0435 \u0447\u0438\u0441\u043b\u043e $W$ (\u0446\u0435\u043b\u043e\u0435, \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 $100$) &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d \u043d\u0430 \u043f\u043e\u043b\u0435, \u0434\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 $W$ \u043f\u0430\u0440 \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043c\u0438\u043d\u044b \u043d\u0430 \u043f\u043e\u043b\u0435 (\u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &#8212; \u0441\u0442\u0440\u043e\u043a\u0430, \u0432\u0442\u043e\u0440\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &#8212; \u0441\u0442\u043e\u043b\u0431\u0435\u0446).<\/p>\n<h2>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h2>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u043f\u043e\u043b\u0435. \u0424\u043e\u0440\u043c\u0430\u0442 \u0432\u044b\u0432\u043e\u0434\u0430 \u0443\u043a\u0430\u0437\u0430\u043d \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<h1>\u0422\u0435\u0441\u0442\u044b<\/h1>\n<p>&nbsp;<\/p>\n<table style=\"height: 198px\" width=\"277\">\n<tbody>\n<tr>\n<th>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<th>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/th>\n<\/tr>\n<tr>\n<td>3 2<br \/>\n2<br \/>\n1 1<br \/>\n2 2<\/td>\n<td>* 2<br \/>\n2 *<br \/>\n1 1<\/td>\n<\/tr>\n<tr>\n<td>2 2<br \/>\n0<\/td>\n<td>0 0<br \/>\n0 0<\/td>\n<\/tr>\n<tr>\n<td>10 10<br \/>\n5<br \/>\n1 1<br \/>\n3 3<br \/>\n5 5<br \/>\n7 7<br \/>\n9 9<\/td>\n<td>* 1 0 0 0 0 0 0 0 0<br \/>\n1 2 1 1 0 0 0 0 0 0<br \/>\n0 1 * 1 0 0 0 0 0 0<br \/>\n0 1 1 2 1 1 0 0 0 0<br \/>\n0 0 0 1 * 1 0 0 0 0<br \/>\n0 0 0 1 1 2 1 1 0 0<br \/>\n0 0 0 0 0 1 * 1 0 0<br \/>\n0 0 0 0 0 1 1 2 1 1<br \/>\n0 0 0 0 0 0 0 1 * 1<br \/>\n0 0 0 0 0 0 0 1 1 1<\/td>\n<\/tr>\n<tr>\n<td>1 1<br \/>\n1<br \/>\n1 1<\/td>\n<td>*<\/td>\n<\/tr>\n<tr>\n<td>32 32<br \/>\n10<br \/>\n1 1<br \/>\n2 2<br \/>\n4 4<br \/>\n4 3<br \/>\n3 4<br \/>\n5 5<br \/>\n27 28<br \/>\n30 30<br \/>\n22 31<br \/>\n32 32<\/td>\n<td>* 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n2 * 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n1 2 4 * 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n0 1 * * 3 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n0 1 2 3 * 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 * 1<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 * 1 0 0 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 * 1 0<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 1<br \/>\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 *<\/td>\n<\/tr>\n<\/tbody>\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.Scanner;\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scanner = new Scanner(System.in);\r\n\t\tint n = scanner.nextInt();\r\n\t\tint m = scanner.nextInt();\r\n\t\tint bomb = scanner.nextInt();\r\n\t\tint count = 0;\r\n\t\tchar[][] A = new char[34][34];\r\n\t\tfor (int i = 0; i &lt; bomb; i++){\r\n        int x = scanner.nextInt();\r\n        int y = scanner.nextInt();\r\n        A[x][y] = '*';\r\n    \t}\r\n    \tfor (int i = 1; i &lt; n + 1; i++){\r\n        for (int j = 1; j &lt; m + 1; j++){ \r\n            if (A[i][j] != '*'){\r\n                if (A[i-1][j] == '*') count++;\r\n                if (A[i-1][j-1] == '*') count++;\r\n                if (A[i-1][j+1] == '*') count++;\r\n                if (A[i+1][j+1] == '*') count++;\r\n                if (A[i+1][j-1] == '*') count++;\r\n                if (A[i+1][j] == '*') count++;\r\n                if (A[i][j-1] == '*') count++;\r\n                if (A[i][j+1] == '*') count++;\r\n                System.out.print(count);\r\n                count = 0;\r\n            }\r\n            else System.out.print(A[i][j]);\r\n            if (j != m) System.out.print(\" \");;\r\n        }\r\n        System.out.print(\"\\n\");\r\n    \t}\r\n\t}\r\n}<\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u043c\u0438\u043d \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0412\u0441\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043f\u043e\u0434 \u043f\u043e\u043b\u0435, \u0438 \u0438\u0445 \u043e\u043a\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0437\u0430\u0431\u043b\u0430\u0433\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043e\u0431\u043d\u0443\u043b\u0438\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d \u043f\u0440\u0438 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0435.<\/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 \u0441\u0430\u0439\u0442\u0435 <a href=\"https:\/\/www.e-olymp.com\/ru\/problems\/2671\">e-olymp<\/a><\/p>\n<p>\u043a\u043e\u0434 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430 <a href=\"https:\/\/ideone.com\/40Kpnw\">ideone<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0414\u0430\u043d \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0438\u043d. \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0438\u0433\u0440\u044b \u0432 \u0441\u0430\u043f\u0435\u0440. \u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0414\u0430\u043d\u044b \u0447\u0438\u0441\u043b\u0430 $N$ \u0438 $M$ (\u0446\u0435\u043b\u044b\u0435, \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435, \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0442 $32$) &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043f\u043e\u043b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0434\u0430\u043b\u0435\u0435 \u0447\u0438\u0441\u043b\u043e $W$ (\u0446\u0435\u043b\u043e\u0435, \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 $100$) &#8212; \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u0438\u043d \u043d\u0430 \u043f\u043e\u043b\u0435, \u0434\u0430\u043b\u0435\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 $W$ \u043f\u0430\u0440 \u0447\u0438\u0441\u0435\u043b, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043c\u0438\u043d\u044b \u043d\u0430 \u043f\u043e\u043b\u0435 (\u043f\u0435\u0440\u0432\u043e\u0435 \u0447\u0438\u0441\u043b\u043e &hellip; <a href=\"https:\/\/java.mazurok.com\/?p=4791\" class=\"more-link\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":126,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,26],"tags":[136,413,677,678],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4791"}],"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\/126"}],"replies":[{"embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4791"}],"version-history":[{"count":1,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4791\/revisions"}],"predecessor-version":[{"id":4792,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=\/wp\/v2\/posts\/4791\/revisions\/4792"}],"wp:attachment":[{"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java.mazurok.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}