博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1054. The Dominant Color (20)
阅读量:5344 次
发布时间:2019-06-15

本文共 1359 字,大约阅读时间需要 4 分钟。

挺简单的,多占内存,少用循环

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, 800x600), 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 (<=800) and N (<=600) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0, 224). 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 30 0 255 16777215 2424 24 0 0 2424 0 24 24 24
Sample Output:
24
来源: <>
 
 
  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. using namespace std;
  4. int a[16777216];
  5. int main(void) {
  6. int m, n;
  7. scanf("%d %d", &m, &n);
  8. int p = m*n,temp,count=0,result=0;
  9. for (int i = 0; i < p; i++) {
  10. scanf("%d", &temp);
  11. a[temp]++;
  12. if (a[temp] > count) {
  13. count = a[temp];
  14. result = temp;
  15. }
  16. }
  17. printf("%d", result);
  18. return 0;
  19. }

转载于:https://www.cnblogs.com/zzandliz/p/5023178.html

你可能感兴趣的文章
[HIHO1184]连通性二·边的双连通分量(双连通分量)
查看>>
Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf 【动态规划】0-1背包
查看>>
SparkStreaming 源码分析
查看>>
【算法】—— 随机音乐的播放算法
查看>>
mysql asyn 示例
查看>>
DataGrid 点击 获取 行 ID
查看>>
git 使用
查看>>
边框圆角方法
查看>>
asp.net WebApi自定义权限验证消息返回
查看>>
php中eval函数的危害与正确禁用方法
查看>>
20172315 2017-2018-2 《程序设计与数据结构》第十一周学习总结
查看>>
MySQL添加、修改、撤销用户数据库操作权限的一些记录
查看>>
ViewBag & ViewData
查看>>
关于谷歌浏览器Chrome正在处理请求的问题解决
查看>>
Git核心技术:在Ubuntu下部署Gitolite服务端
查看>>
平面波展开法总结
查看>>
建造者模式
查看>>
ArraySort--冒泡排序、选择排序、插入排序工具类demo
查看>>
composer 安装laravel
查看>>
8-EasyNetQ之Send & Receive
查看>>