1054 The Dominant Color (20 分)
 

Behind the scenes in the computer'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 strictly dominant color takes more than half of the total area. Now given an image of resolution M by N (for example, 8), you are supposed to point out the strictly dominant color.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive numbers: M (≤) and N (≤) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0). It is guaranteed that the strictly dominant color exists for each input image. All the numbers in a line are separated by a space.

Output Specification:

For each test case, simply print the dominant color in a line.

Sample Input:

5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24

Sample Output:

24

题意

  给出一张图片的分辨率,在下面的n行m列中给出每个像素点的颜色编码,最后输出数量最多的颜色的编码。

思路:

  用map记录每个颜色出现的次数,很容易实现输出出现次数最多颜色。

  第一次失误写成了 cout<<color; 竟然AC了。。。难道每个测试用例最后输入的颜色就是答案?把map去掉只留下输入color输出color,还真的全部AC。可惜输入m*n个数时间复杂度还是O(m*n),跟原来的耗时没什么区别,暂时还没什么方法把时间复杂度降到O(1)。

code:

 #include<bits/stdc++.h>
using namespace std;
map<int, int> colorMap;
int main(){
int m, n, color, domin = ;
cin>>m>>n;
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
cin>>color;
colorMap[color]++;
if(colorMap[domin] < colorMap[color]) domin = color;
}
}
cout<<domin;
return ;
}

【算法笔记】A1054 The Dominant Color的更多相关文章

  1. A1054. The Dominant Color

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

  2. PAT甲级——A1054 The Dominant Color

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

  3. 1054. The Dominant Color (20)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...

  4. 学习Java 以及对几大基本排序算法(对算法笔记书的研究)的一些学习总结(Java对算法的实现持续更新中)

    Java排序一,冒泡排序! 刚刚开始学习Java,但是比较有兴趣研究算法.最近看了一本算法笔记,刚开始只是打算随便看看,但是发现这本书非常不错,尤其是对排序算法,以及哈希函数的一些解释,让我非常的感兴 ...

  5. PAT 1054 The Dominant Color

    1054 The Dominant Color (20 分)   Behind the scenes in the computer's memory, color is always talked ...

  6. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  7. PAT 1054 The Dominant Color[简单][运行超时的问题]

    1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...

  8. 算法笔记--数位dp

    算法笔记 这个博客写的不错:http://blog.csdn.net/wust_zzwh/article/details/52100392 数位dp的精髓是不同情况下sta变量的设置. 模板: ]; ...

  9. 算法笔记--lca倍增算法

    算法笔记 模板: vector<int>g[N]; vector<int>edge[N]; ][N]; int deep[N]; int h[N]; void dfs(int ...

随机推荐

  1. python高性能编程方法一-乾颐堂

    阅读 Zen of Python,在Python解析器中输入 import this. 一个犀利的Python新手可能会注意到"解析"一词, 认为Python不过是另一门脚本语言. ...

  2. QTcpSocket-Qt使用Tcp通讯实现服务端和客户端

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:QTcpSocket-Qt使用Tcp通讯实现服务端和客户端     本文地址:https:// ...

  3. Java 设计模式系列(九)组合模式

    Java 设计模式系列(九)组合模式 将对象组合成树形结构以表示"部分-整体"的层次结构.组合模式使得用户对单个对象的使用具有一致性. 一.组合模式结构 Component: 抽象 ...

  4. oracle RAC 创库,停启库,删除库

    1.创建数据库的命令dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname FPCSDB2 -sid FPCSD ...

  5. linux每天一小步---ls命令详解

    1 命令功能: 列出当前目录下或者指定目录下的所有文件和目录,ls是list的缩写. 2 命令语法: ls [选项] [目录名]     #注:[]中的内容为非必选项 3 命令选项: -a 列出目录下 ...

  6. Photoshop 原画绘制

    ... <伯里曼> 手绘.鼠绘和板绘.

  7. jmeter 各种配置修修改(后续增加)

    1.修改物理内存  使用jmeter进行压力测试时遇到一段时间后报内存溢出outfmenmory错误,导致jmeter卡死了,先尝试在jmeter.bat中增加了JVM_ARGS="-Xmx ...

  8. [label][Chrome-Extension] How to start Chrome Extension's development

    Firstly , you should read these two pages.  https://developer.chrome.com/extensions/overview https:/ ...

  9. 修改VS中的附加依赖项的继承值

    工程用不到的库,想去都去不掉,一直链接错误... 解决方法:打开vs的“属性管理器”窗口.通过这个窗口就可以对里面的继承值进行编辑了 另,“属性管理器”这个窗口,一般在“其他窗口”选项里(至少VS20 ...

  10. PG数据库错误: 检测到OA幸运飞艇源码ShareLock死锁处理

    PostgreSQL 是一个免费数据库,OA幸运飞艇源码下载,详情咨询[企娥166848365]对于处理分析型+交易型混合型系统来说确实很不错,特别是版本的升级到11.2后性能提升很多,很多运行机制跟 ...