{"id":472,"date":"2019-02-11T22:59:16","date_gmt":"2019-02-11T13:59:16","guid":{"rendered":"http:\/\/www.mukgee.com\/?p=472"},"modified":"2020-12-27T01:24:31","modified_gmt":"2020-12-26T16:24:31","slug":"%ec%95%8c%ea%b3%a0%eb%a6%ac%ec%a6%98%ea%b0%95%eb%b3%80-%ec%a1%b0%eb%a7%9d%ea%b6%8c-%ea%b5%ac%ed%95%98%eb%8a%94-%eb%ac%b8%ec%a0%9c","status":"publish","type":"post","link":"http:\/\/mukgee.com\/?p=472","title":{"rendered":"[\uc54c\uace0\ub9ac\uc998]\uac15\ubcc0 \uc870\ub9dd\uad8c \uad6c\ud558\ub294 \ubb38\uc81c"},"content":{"rendered":"<p>\ubb38\uc81c\ub97c \uc694\uc57d\ud558\uba74 \uac15\ubcc0\uc5d0 \uac74\ubb3c\uc774 \ub298\uc5b4\uc11c \uc788\ub294\ub370,<\/p>\n<p>\uc88c\/\uc6b0 \ub85c 2\uce78\uc529 \uacf5\uac04\uc774 \uc788\uc5b4\uc57c \uc870\ub9dd\uad8c\uc774 \ud655\ubcf4 \ub418\uc5c8\ub2e4\uace0 \ud310\ub2e8\ud569\ub2c8\ub2e4.<\/p>\n<p>\uc785\ub825\ub41c \uac12\ub4e4\uc744 \uc21c\uc11c\ub300\ub85c \ube4c\ub529\uc758 \uce35\uc218\ub77c\uace0 \ud560\ub54c \uc870\ub9dd\uad8c\uc774 \ud655\ubcf4\ub41c \uce35\uc218\uc758 \ud569\uc744 \uad6c\ud558\ub294 \ubb38\uc81c\uc785\ub2c8\ub2e4.<\/p>\n<p>Greedy \uc54c\uace0\ub9ac\uc998\uc73c\ub85c \uccab\ubc88\uc9f8 \ub450\ubc88\uc9f8\ub97c Case\ub97c \uacc4\uc0b0\ud558\uba70 \ub2f5\uc744 \ucc3e\ub294 \uc218\uc2dd \ucc3e\uc558\uc2b5\ub2c8\ub2e4.<\/p>\n<p>result = Min( a &#8211; Max( a-2 , a-1) , a &#8211; Max(a+1, a+2) )\u00a0if result &gt; 0<\/p>\n<p>\uc2dc\uac04 \ubcf5\uc7a1\ub3c4\ub294 O(n) \uc778\ub370 \uac1c\uc120 \uac00\ub2a5\ud55c \ubc29\ubc95\uc744 \uace0\ubbfc\uc911\uc774\ub098 \ucc3e\uc9c0 \ubabb\ud558\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<p>&nbsp;<\/p>\n<p>\uad6c\uae00\ub9c1\ud588\uc744\ub54c \ub098\uc628 \ub2f5\ubcf4\ub2e4\ub294 \uc774 \ucf54\ub4dc\uac00 \ub098\uc740\uac70 \uac19\uc740\ub370.. \uc88b\uc740 \ucf54\ub4dc \uc788\uc73c\uba74 \uacf5\uc720 \ubd80\ud0c1\ub4dc\ub9bd\ub2c8\ub2e4.<\/p>\n<pre class=\"lang:java decode:true\">import java.util.Scanner;\n\npublic class Solution{\n    \n    private final static int testCase = 10;\n    \n    public static void main(String[] args){\n        Scanner sc = new Scanner(System.in);\n        Solution mh = new Solution();\n        for(int inx = 0 ; inx &lt; testCase ; inx++){\n            String input1 = sc.nextLine();\n            String input2 = sc.nextLine();\t\n            int buildingNo = Integer.parseInt(input1);\n            String[] buildings = input2 != null ? input2.split(\" \") : null;\n            \n            int result = 0;\n            if(buildings == null) continue;\n            \n            for(int inj = 2; inj &lt; buildings.length-2 ; inj++){   \n                int testBuilding = Integer.parseInt(buildings[inj]);\n                int temp = mh.getMinValue( testBuilding - mh.getMaxValue(buildings[inj-2] , buildings[inj-1]), testBuilding- mh.getMaxValue(buildings[inj+1] , buildings[inj+2]));\n                if(temp &gt; 0 ) result += temp;\n            }\n            System.out.println(\"#\"+String.valueOf(inx+1) + \" \" + String.valueOf(result));  \n        }\n    }\n    \n        public int getMaxValue(String a, String b){\n            int a1 = Integer.parseInt(a);\n            int b1 = Integer.parseInt(b);\n            return a1 &gt; b1 ? a1 : b1;\n        }\n\n        public int getMinValue(int a, int b){\n            return a &lt; b ? a : b;\n        }\n    \n}<\/pre>\n<p>\ucd9c\ucc98 :\u00a0https:\/\/www.swexpertacademy.com\/main\/code\/problem\/problemDetail.do?contestProbId=AV134DPqAA8CFAYh&amp;categoryId=AV134DPqAA8CFAYh&amp;categoryType=CODE<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ubb38\uc81c\ub97c \uc694\uc57d\ud558\uba74 \uac15\ubcc0\uc5d0 \uac74\ubb3c\uc774 \ub298\uc5b4\uc11c \uc788\ub294\ub370, \uc88c\/\uc6b0 \ub85c 2\uce78\uc529 \uacf5\uac04\uc774 \uc788\uc5b4\uc57c \uc870\ub9dd\uad8c\uc774 \ud655\ubcf4 \ub418\uc5c8\ub2e4\uace0 \ud310\ub2e8\ud569\ub2c8\ub2e4. \uc785\ub825\ub41c \uac12\ub4e4\uc744 \uc21c\uc11c\ub300\ub85c \ube4c\ub529\uc758 \uce35\uc218\ub77c\uace0 \ud560\ub54c \uc870\ub9dd\uad8c\uc774 \ud655\ubcf4\ub41c \uce35\uc218\uc758 \ud569\uc744&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[3],"tags":[53],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/posts\/472"}],"collection":[{"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mukgee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":1,"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":613,"href":"http:\/\/mukgee.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions\/613"}],"wp:attachment":[{"href":"http:\/\/mukgee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mukgee.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mukgee.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}