{"id":604,"date":"2013-09-10T18:34:22","date_gmt":"2013-09-10T10:34:22","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=604"},"modified":"2013-09-10T18:34:22","modified_gmt":"2013-09-10T10:34:22","slug":"1054-the-dominant-color-20","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=604","title":{"rendered":"1054. The Dominant Color (20)"},"content":{"rendered":"<p>\u65f6\u95f4\u9650\u5236\uff1a100ms<br \/>\nBehind the scenes in the computer&#8217;s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A\u00a0<i>strictly<\/i>\u00a0dominant color takes more than half of the total area. Now given an image of resolution M by N (for example, 800&#215;600), you are supposed to point out the strictly dominant color.<br \/>\n<b>Input Specification:<\/b><br \/>\nEach input file contains one test case. For each case, the first line contains 2 positive numbers: M (&lt;=800) and N (&lt;=600) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0, 2<sup>24<\/sup>). It is guaranteed that the strictly dominant color exists for each input image. All the numbers in a line are separated by a space.<br \/>\n<b>Output Specification:<\/b><br \/>\nFor each test case, simply print the dominant color in a line.<br \/>\n<b>Sample Input:<\/b><\/p>\n<pre>5 3\n0 0 255 16777215 24\n24 24 0 0 24\n24 0 24 24 24<\/pre>\n<p><b>Sample Output:<\/b><\/p>\n<pre>24<\/pre>\n<p>==============================<br \/>\n\u8fd9\u9898\u76ee\u5c31\u662f\u4e2a\u6295\u7968\u9009\u73ed\u957f\u7684\u9898\u76ee\uff0c\u4e0a\u4e2a\u5b66\u671f\u6570\u636e\u5e93\u8001\u5e08\u8bfe\u4e0a\u8bb2\u8fc7\uff08\u53ef\u60dc\u4e86\uff0c\u6570\u636e\u5e93\u540e\u6765\u6ca1\u8003\u597d\uff09\uff0c\u77ac\u95f4\u72b9\u5982\u918d\u9190\u704c\u9876~<br \/>\n<quote><br \/>\n\u918d\u9190\u704c\u9876\uff0c\u51fa\u4e8e\u300a\u6566\u714c\u53d8\u6587\u96c6\u00b7\u7ef4\u6469\u8bd8\u7ecf\u8bb2\u7ecf\u6587\u300b\uff1a\u201c\u4ee4\u95ee\u7ef4\u6469\uff0c\u95fb\u540d\u4e4b\u5982\u9732\u5165\u5fc3\uff0c\u5171\u8bed\u4f3c\u918d\u9190\u704c\u9876\u3002\u201d\u4f5b\u6559\u6307\u704c\u8f93\u667a\u6167\uff0c\u4f7f\u4eba\u5f7b\u5e95\u89c9\u609f\u3002\u6bd4\u55bb\u542c\u4e86\u9ad8\u660e\u7684\u610f\u89c1\u4f7f\u4eba\u53d7\u5230\u5f88\u5927\u542f\u53d1\u3002<br \/>\n<\/quote><br \/>\n\u6700\u7b28\u7684\u529e\u6cd5\u662f\u6bcf\u4e2a\u4eba\u753b\u6b63\u5b57\uff0c\u6d6a\u8d39\u7a7a\u95f4\uff0c\u6700\u540e\u8fd8\u8981\u7edf\u8ba1\u7968\u6570<br \/>\n\u6700\u7ec8\u7684\u76ee\u7684\u662f\u8981\u9009\u51fa\u7968\u6570\u6700\u591a\u7684\u4e00\u4e2a\u4eba\uff0c\u90a3\u4e48\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<br \/>\n<code><br \/>\n\u521d\u59cb\u5316:<br \/>\n\u73ed\u957f\u5019\u9009\u4eba\uff1a\u53c9\u53c9\u53c9<br \/>\n\u5f53\u524d\u5dee\u989d\u7968\u6570\uff1a1<br \/>\n\u7136\u540e\u62ff\u4e00\u5f20\u9009\u7968\uff0c\u7968\u9762\u4e0a\u7684\u540d\u5b57\u662fName<br \/>\nif Name == \u5f53\u524d\u7684\u5019\u9009\u4eba:<br \/>\n   \u5dee\u989d\u7968\u6570++<br \/>\nelse:<br \/>\n   \u5dee\u989d\u7968\u6570--<br \/>\n   if \u5dee\u989d\u7968\u6570==0:<br \/>\n      \u5019\u9009\u4eba = Name<br \/>\n      \u5dee\u989d\u7968\u6570 = 1<br \/>\n<\/code><br \/>\n\u8fd9\u6837\u7684\u8bdd\uff0c\u7701\u65f6\u95f4\u4e5f\u7701\u7a7a\u95f4:)<br \/>\n\u539f\u7406\u5176\u5b9e\u60f3\u901a\u4e86\u5f88\u7b80\u5355\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9009\u4e00\u4e2a\u4eba\u554a\uff0c\u53ea\u7b97\u51c0\u80dc\u7968\u6570\u5c31\u884c<br \/>\n\u51c0\u80dc\u7968\u6570\u4e3a0\u4e86\uff0c\u90a3\u5c31\u8981\u88ab\u8d76\u4e0b\u53f0\u4e86\uff01<br \/>\n\u4ece\u6d4b\u8bd5\u70b9\u7684\u7ed3\u679c\u6765\u770b\uff0c\u7684\u786e\u6709\u4e2a\u6d4b\u8bd5\u70b9\u6570\u636e\u91cf\u633a\u5927\u7684&#8230;\u4f30\u8ba1\u4e4b\u524d\u8bf4\u7684\u7b28\u529e\u6cd5\u5c31\u8981\u8d85\u65f6\u4e86..<br \/>\n=================================<br \/>\n<code lang=\"c++\"><br \/>\n#include <stdio.h><br \/>\nint main()<br \/>\n{<br \/>\n\tint M, N;<br \/>\n\tscanf(\"%d %d\", &M, &N);<br \/>\n\tint resolution = M * N;<br \/>\n\tint currBest = -1;<br \/>\n\tint currCount = 1;<br \/>\n\tfor(int i=0; i<resolution; i++)\n\t{\n\t\tint readVal;\n\t\tscanf(\"%d\", &#038;readVal);\n\t\tif(currBest != readVal)\n\t\t{\n\t\t\tcurrCount--;\n\t\t\tif(currCount == 0)\n\t\t\t{\n\t\t\t\tcurrBest = readVal;\n\t\t\t\tcurrCount++;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t\tcurrCount ++;\n\t}\n\tprintf(\"%d\", currBest);\n\treturn 0;\n}\n<\/code><\/p>\n<pre>\n\u6d4b\u8bd5\u70b9\t\u7ed3\u679c\t\u7528\u65f6(ms)\t\u5185\u5b58(kB)\t\u5f97\u5206\/\u6ee1\u5206\n0\t\u7b54\u6848\u6b63\u786e\t0\t790\t12\/12\n1\t\u7b54\u6848\u6b63\u786e\t0\t790\t2\/2\n2\t\u7b54\u6848\u6b63\u786e\t60\t780\t2\/2\n3\t\u7b54\u6848\u6b63\u786e\t0\t790\t2\/2\n4\t\u7b54\u6848\u6b63\u786e\t0\t710\t2\/2\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u65f6\u95f4\u9650\u5236\uff1a100ms Behind the scenes in the computer&#8217;s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A\u00a0strictly\u00a0dominant color takes more than half of the total area. Now given an image of resolution [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[84],"class_list":["post-604","post","type-post","status-publish","format-standard","hentry","category-study","tag-pat"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=604"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/604\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}