{"id":327,"date":"2013-08-01T12:52:29","date_gmt":"2013-08-01T16:52:29","guid":{"rendered":"http:\/\/www.ferociouscoder.com\/blog\/?p=327"},"modified":"2013-08-02T22:18:01","modified_gmt":"2013-08-03T02:18:01","slug":"uva-12247-jollo","status":"publish","type":"post","link":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html","title":{"rendered":"UVA 12247 &#8211; Jollo"},"content":{"rendered":"<p>I lazily figured out weather a given nubmer was good enough or not by trying all combinations. I&#8217;m sure there&#8217;s a better (greedy) way to do this that involves less work. Greedy doesn&#8217;t always work, but though so be careful! I messed up twice by trying a greedy strategy and gave up when I got tired of finding something that has no counterexamples.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nimport java.io.PrintWriter;\r\nimport java.util.Arrays;\r\nimport java.util.Scanner;\r\n\r\n\/**\r\n * \r\n * @author Sanchit M. Bhatnagar\r\n * @see http:\/\/uhunt.felix-halim.net\/id\/74004\r\n * \r\n *\/\r\npublic class P12247 {\r\n\r\n  public static void main(String&#x5B;] args) {\r\n    Scanner sc = new Scanner(System.in);\r\n    PrintWriter out = new PrintWriter(System.out);\r\n\r\n    while (sc.hasNext()) {\r\n      int&#x5B;] princess = new int&#x5B;] { sc.nextInt(), sc.nextInt(), sc.nextInt() };\r\n      if (princess&#x5B;0] == 0)\r\n        break;\r\n      int&#x5B;] prince = new int&#x5B;] { -1, sc.nextInt(), sc.nextInt() };\r\n      out.println(check(princess, prince));\r\n    }\r\n\r\n    out.close();\r\n    sc.close();\r\n  }\r\n\r\n  \/\/ Cheating\r\n  private static int&#x5B;]&#x5B;] perm = { new int&#x5B;] { 0, 1, 2 }, new int&#x5B;] { 0, 2, 1 }, new int&#x5B;] { 1, 0, 2 }, new int&#x5B;] { 1, 2, 0 }, new int&#x5B;] { 2, 0, 1 }, new int&#x5B;] { 2, 1, 0 } };\r\n\r\n  private static int check(int&#x5B;] princess, int&#x5B;] prince) {\r\n    int&#x5B;] tmpPrincess = Arrays.copyOf(princess, princess.length);\r\n    int&#x5B;] tmpPrince = null;\r\n    int min = 1;\r\n    boolean found = false;\r\n    for (int i = min; !found &amp;&amp; i &lt;= 52; i++) {\r\n      tmpPrince = Arrays.copyOf(prince, prince.length);\r\n      tmpPrince&#x5B;0] = i;\r\n      if (i != tmpPrincess&#x5B;0] &amp;&amp; i != tmpPrincess&#x5B;1] &amp;&amp; i != tmpPrincess&#x5B;2] &amp;&amp; i != tmpPrince&#x5B;1] &amp;&amp; i != tmpPrince&#x5B;2]) {\r\n        min = i;\r\n        \/\/ Try to lose\r\n        int count = 0;\r\n        for (int j = 0; count == 0 &amp;&amp; j &lt; perm.length; j++) {\r\n          int subCount = 0;\r\n          for (int k = 0; k &lt; 3; k++) {\r\n            if (tmpPrince&#x5B;perm&#x5B;j]&#x5B;k]] &gt; tmpPrincess&#x5B;k]) {\r\n              subCount++;\r\n            }\r\n          }\r\n          if (subCount &lt; 2)\r\n            count++;\r\n        }\r\n        if (count == 0)\r\n          found = true;\r\n      }\r\n    }\r\n    if (!found) {\r\n      return -1;\r\n    } else {\r\n      return min;\r\n    }\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I lazily figured out weather a given nubmer was good enough or not by trying all combinations. I&#8217;m sure there&#8217;s a better (greedy) way to do this that involves less work. Greedy doesn&#8217;t always work, but though so be careful! I messed up twice by trying a greedy strategy and gave up when I got &hellip; <a href=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">UVA 12247 &#8211; Jollo<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,19,17],"tags":[21,20,22],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-competitive-programming-3","category-java","category-uva-online-judge","tag-competitive-programming-3-2","tag-java-2","tag-uva-online-judge-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>UVA 12247 - Jollo - Ferocious Coder<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"UVA 12247 - Jollo - Ferocious Coder\" \/>\n<meta property=\"og:description\" content=\"I lazily figured out weather a given nubmer was good enough or not by trying all combinations. I&#8217;m sure there&#8217;s a better (greedy) way to do this that involves less work. Greedy doesn&#8217;t always work, but though so be careful! I messed up twice by trying a greedy strategy and gave up when I got &hellip; Continue reading UVA 12247 &#8211; Jollo &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html\" \/>\n<meta property=\"og:site_name\" content=\"Ferocious Coder\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-01T16:52:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-03T02:18:01+00:00\" \/>\n<meta name=\"author\" content=\"Rawrosaur\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rawrosaur\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html\"},\"author\":{\"name\":\"Rawrosaur\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"headline\":\"UVA 12247 &#8211; Jollo\",\"datePublished\":\"2013-08-01T16:52:29+00:00\",\"dateModified\":\"2013-08-03T02:18:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html\"},\"wordCount\":275,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"keywords\":[\"competitive programming 3\",\"java\",\"uva online judge\"],\"articleSection\":[\"Competitive Programming 3\",\"Java\",\"UVA Online Judge\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html\",\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html\",\"name\":\"UVA 12247 - Jollo - Ferocious Coder\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#website\"},\"datePublished\":\"2013-08-01T16:52:29+00:00\",\"dateModified\":\"2013-08-03T02:18:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/uva-12247-jollo-327.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"UVA 12247 &#8211; Jollo\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/\",\"name\":\"Ferocious Coder\",\"description\":\"RAWR!\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/#\\\/schema\\\/person\\\/1fb5cbee546cffd619a7b301e3dc447a\",\"name\":\"Rawrosaur\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\",\"caption\":\"Rawrosaur\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg\"},\"sameAs\":[\"http:\\\/\\\/www.ferociouscoder.com\\\/\"],\"url\":\"https:\\\/\\\/www.ferociouscoder.com\\\/blog\\\/archives\\\/author\\\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"UVA 12247 - Jollo - Ferocious Coder","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html","og_locale":"en_US","og_type":"article","og_title":"UVA 12247 - Jollo - Ferocious Coder","og_description":"I lazily figured out weather a given nubmer was good enough or not by trying all combinations. I&#8217;m sure there&#8217;s a better (greedy) way to do this that involves less work. Greedy doesn&#8217;t always work, but though so be careful! I messed up twice by trying a greedy strategy and gave up when I got &hellip; Continue reading UVA 12247 &#8211; Jollo &rarr;","og_url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html","og_site_name":"Ferocious Coder","article_published_time":"2013-08-01T16:52:29+00:00","article_modified_time":"2013-08-03T02:18:01+00:00","author":"Rawrosaur","twitter_misc":{"Written by":"Rawrosaur","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html#article","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html"},"author":{"name":"Rawrosaur","@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"headline":"UVA 12247 &#8211; Jollo","datePublished":"2013-08-01T16:52:29+00:00","dateModified":"2013-08-03T02:18:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html"},"wordCount":275,"commentCount":1,"publisher":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"keywords":["competitive programming 3","java","uva online judge"],"articleSection":["Competitive Programming 3","Java","UVA Online Judge"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html","url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html","name":"UVA 12247 - Jollo - Ferocious Coder","isPartOf":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#website"},"datePublished":"2013-08-01T16:52:29+00:00","dateModified":"2013-08-03T02:18:01+00:00","breadcrumb":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.ferociouscoder.com\/blog\/archives\/uva-12247-jollo-327.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.ferociouscoder.com\/blog"},{"@type":"ListItem","position":2,"name":"UVA 12247 &#8211; Jollo"}]},{"@type":"WebSite","@id":"https:\/\/www.ferociouscoder.com\/blog\/#website","url":"https:\/\/www.ferociouscoder.com\/blog\/","name":"Ferocious Coder","description":"RAWR!","publisher":{"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.ferociouscoder.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.ferociouscoder.com\/blog\/#\/schema\/person\/1fb5cbee546cffd619a7b301e3dc447a","name":"Rawrosaur","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg","caption":"Rawrosaur"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/1372156bd3b16de375c8727c2c617467bf6ff38f1679a7912f48286349c17e96?s=96&d=retro&r=pg"},"sameAs":["http:\/\/www.ferociouscoder.com\/"],"url":"https:\/\/www.ferociouscoder.com\/blog\/archives\/author\/admin"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1mYMV-5h","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":2,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":334,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions\/334"}],"wp:attachment":[{"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ferociouscoder.com\/blog\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}