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. Luogu 5170 【模板】类欧几里得算法

    原理不难但是写起来非常复杂的东西. 我觉得讲得非常好懂的博客.   传送门 我们设 $$f(a, b, c, n) = \sum_{i = 0}^{n}\left \lfloor \frac{ai + ...

  2. 命令: go build

    命令: go build 参考: https://studygolang.com/articles/9463 go help build 构建编译由导入路径命名的包,以及它们的依赖关系,但它不会安装结 ...

  3. MyBatis 插入主键方式和返回主键

    这使用的mysql数据库,下面这种方式(没有给mysql设置自动增长)是插入主键方式: <insert id="insertBook" parameterType=" ...

  4. pycharm控制台出现python编译器的编辑功能

    一.最近研究了下python,然后昨天发现新建项目后,出现如图的输入状况(Ctrl+Alt+F10) 二 二.更改方式 (1)点开如图位置,进入编辑模式 (2)将如图位置的√去掉就好了

  5. UVa 1599 Ideal Path (两次BFS)

    题意:给出n个点,m条边的无向图,每条边有一种颜色,求从结点1到结点n颜色字典序最小的最短路径. 析:首先这是一个最短路径问题,应该是BFS,因为要保证是路径最短,还要考虑字典序,感觉挺麻烦的,并不好 ...

  6. Spring 之 IOC

    IoC的全称是Inversion of Control,中文称为控制反转, Martin Flower由根据它创造了一个新词:Dependency Injection,中文称为依赖注入.这两个词讲的是 ...

  7. EBS11i - 常用Profile

      Profile Name 说明 设置建议 FND: Enable Cancel Query 当执行一个超长时间的查询时,会出现一个 Cancel窗口,允许用户取消.比如我们在SO 界面没有输入条件 ...

  8. delphi FastReport 安装方法

    (最近记忆力真的不行了,装了很多遍,过段时间重装delphi又不记得了,又要折腾,现在先记录下来,留给下次翻) 1.下载安装包,这里提供一个百度云盘共享链接,版本为fastreport5: https ...

  9. Python学习-8.Python的循环语句-while语句

    例子: i = 1 while i < 10: print(i) i+=1 else: print('finish') 输出1至9和finish 在while语句中同样支持for语句所支持的co ...

  10. pssh执行本地文件(脚本)

    场景:目标命令中含有特殊符号,导致pssh批量执行可能出问题. 用法: pssh -h RemoteHosts.ip -P -I < ~/LocalScript.sh