pat 1054 The Dominant Color(20 分)
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, 800×600), 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 <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
using namespace std;
const int MAX = 1e7 + ; int n, m, t, a, ans;
bool flag = false;
map <int, int> mp; int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%d%d", &n, &m);
t = ((n * m) & ? ((n * m) / ) + : ((n * m) / ));
for (int i = ; i < m; ++ i)
for (int j = ; j < n; ++ j)
{
scanf("%d", &a);
if (flag) continue;
mp[a] ++;
if (mp[a] >= t)
{
flag = true;
ans = a;
}
}
printf("%d\n", ans);
return ;
}
pat 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 ...
- 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 分)
题意: 输入两个正整数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
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 ...
- 1054. The Dominant Color (20)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...
- PAT甲题题解-1054. The Dominant Color (20)-排序/map
原本用map,发现超时了,后来便先用数组存储排个序,最后for一遍统计每种颜色出现的次数(每种颜色的首位索引相减+1),找出最多的即可. #include <iostream> #incl ...
随机推荐
- 新手也能看懂的 SpringBoot 异步编程指南
本文已经收录自 springboot-guide : https://github.com/Snailclimb/springboot-guide (Spring Boot 核心知识点整理. 基于 S ...
- PHP JSON乱码简洁的解决办法
PHP JSON乱码简洁的解决办法 $arr = array('ret'=>400, 'msg'=>'服务器地址不允许', 'data'=>''); foreach ( $arr a ...
- unity 动画 音频播放
采用Unity进行音频动画的播放时最常用的技术,在此进行一下简单讲解与应用. (一)动画播放(本文采用animation进行验证,关于animation和animator区别可问度娘,在此不做赘述) ...
- GCC中,可以使用未声明过的函数
今天代码中使用了一个函数,这个函数也是自定义的,但是还没来得及声明和定义,可以编译时竟然未报错,网上查了下果然,GCC中可以使用未声明的函数http://bbs.csdn.net/topics/390 ...
- iOS 原生库对 https 的处理
转载自:swift cafe 使用 NSURLSession NSURLSession 是 iOS 原生提供的网络处理库.它提供了丰富的接口以及配置选项,满足我们平时网络处理的大部分需求,同时它也支持 ...
- Spring Boot项目中如何定制servlet-filters
本文首发于个人网站:Spring Boot项目中如何定制servlet-filters 在实际的web应用程序中,经常需要在请求(request)外面增加包装用于:记录调用日志.排除有XSS威胁的字符 ...
- WebApi -用户登录后SessionId未更新
描工具检测出.net的程序有会话标识未更新这个漏洞 用户尚未登录时就有session cookie产生.可以尝试在打开页面的时候,让这个cookie过期.等到用户再登陆的时候就会生成一个新的sessi ...
- 浅谈Retinex
Retinex是上个世纪七十年代由Land提出的色彩理论.我认为其核心思想基于俩点 (1)在颜色感知时,人眼对局部相对光强敏感程度要优于绝对光强. (2)反射分量R(x,y)储存有无光源物体的真实模样 ...
- MIT线性代数:21.特征值和特征向量
- Django学习day8——admin后台管理和语言适应
Django最大的优点之一,就是体贴的为你提供了一个基于项目model创建的一个后台管理站点admin.这个界面只给站点管理员使用,并不对大众开放. 1. 创建管理员用户 (django) E:\Dj ...