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, 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 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
Sample Output:
24
#include<stdio.h>
#include<map>
using namespace std;
int main()
{
int n,m;
map<int,int> mm;
scanf("%d%d",&n,&m);
for(int i = ;i<m*n;i++)
{
int tem;
scanf("%d",&tem);
++mm[tem];
} int MAX = -;
map<int,int>::iterator it;
int index;
for(it = mm.begin();it != mm.end();it ++)
{
if(it->second > MAX)
{
MAX = it ->second;
index = it ->first;
}
} printf("%d\n",index);
return ;
}
1054. The Dominant Color (20)的更多相关文章
- PAT 甲级 1054 The Dominant Color (20 分)(简单题)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- 1054 The Dominant Color (20)(20 分)
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...
- PAT (Advanced Level) Practice 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 i ...
- 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 i ...
- PAT甲题题解-1054. The Dominant Color (20)-排序/map
原本用map,发现超时了,后来便先用数组存储排个序,最后for一遍统计每种颜色出现的次数(每种颜色的首位索引相减+1),找出最多的即可. #include <iostream> #incl ...
- PAT (Advanced Level) 1054. The Dominant Color (20)
简单题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #inc ...
- 【PAT甲级】1054 The Dominant Color (20 分)
题意: 输入两个正整数M和N(M<=800,N<=600),分别代表一张图片的宽度和高度,接着输入N行每行包括M个点的颜色编号,输出这张图片主导色的编号.(一张图片的主导色占据了一半以上的 ...
- PAT 1054 The Dominant Color[简单][运行超时的问题]
1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
随机推荐
- 前端必会css整理
1.设置css样式的三种方式? 外部样式表,引入一个外部css文件 内部样式表,将css代码放在<head>标签内部 内联样式,将css样式 ...
- scrapy yield Request
import scrapy from myproject.items import MyItem class MySpider(scrapy.Spider): name = ’example.com’ ...
- [课程相关]homework-05
零.准备工作 队伍成员:梁杰,夏天晗,谢祖三. 周五晚上吃完饭,我们就开始了讨论. 这次的要求是写服务器,客户端以及游戏结果动态显示.很明显是三个部分,我们也就顺其自然, 一人一个部分.我负责服务器, ...
- iOS通过UIAlertController弹出底部选择框来调用相机或者相册
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredSt ...
- Bash循环分类介绍
方法一: #!/bin/bash ` do #code here echo $i done 方法二:C语言风格 #!/bin/bash ; i<=; i++)) do printf " ...
- CSS3秘笈第三版涵盖HTML5学习笔记9~12章
第9章,装饰网站导航 限制访问,处于隐私方面考虑,浏览器已经开始限制可以对伪类:visited应用哪些CSS属性了.其中包括对已访问过的链接定义color.background-color.borde ...
- jquery里的宽度详解
在jQuery中,width()方法用于获得元素宽度:innerWidth()方法用于获得包括内边界(padding)的元素宽度,outerWidth()方法用于获得包括内边界(padding)和边框 ...
- ios Swift 之github
1. 软件类 a) 作者集合 http://nondot.org/sabre/ b) swift for facebook SWIFT是一个易于使用的,基于注解的Java来创建勤俭节约序列化类型和服务 ...
- Foundation与Core Foundation内存管理基本原则简述
内存管理是一个十分重要的事情,稍有不慎就会发生内存泄漏或者是野指针的错误.内存泄漏一般表示没有任何指针指向的内存区域,由于这块内存在对象图中无法查找到,所以有可能永远都无法回收,如果内存泄漏的空间比较 ...
- iOS开发——消息推送跳转
项目开发用集成是极光推送JPush 这里主要是消息推送过来处理对应界面跳转 同时看到两篇写的不错的相关博客分享一下: http://www.jianshu.com/ ...