PAT 甲级 1054 The Dominant Color
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768
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, 2^24^). 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 <bits/stdc++.h>
using namespace std; int a[801][801];
map<int, int> mp; int main() {
int n, m;
scanf("%d%d", &m, &n);
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
scanf("%d", &a[i][j]);
mp[a[i][j]] ++;
}
} int zlr;
int cnt = 0;
for(int i = 1; i <= n; i ++) {
for(int j = 1; j <= m; j ++) {
if(mp[a[i][j]] > cnt) {
cnt = mp[a[i][j]];
zlr = a[i][j];
}
}
}
printf("%d\n", zlr); return 0;
}
PAT 甲级 1054 The Dominant Color的更多相关文章
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- PAT 甲级 1054 The Dominant Color (20 分)(简单题)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- 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 ...
- 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 ...
- pat 1054 The Dominant Color(20 分)
1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked abo ...
- 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)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...
- 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 ...
随机推荐
- python学习笔记:第9天 函数初步
1. 函数的定义及调用 函数:所谓的函数可以看作是对一段代码的封装,也是对一个功能模块的封装,这样方便在下次想用这个功能的时候直接调用这个功能模块,而不用重新去写. 函数的定义:我们使用def关键字来 ...
- sqlserver之group by 与over函数
group by 函数主要用来对数据进行分组,over()函数则是一个“开窗函数”,它更多的是与聚合函数如:sum().max().min().avg().count()等函数以及排名函数如:row_ ...
- flex 自定义tooltip
//flex用例网址 http://thanksmister.com/2012/01/18/flex-chart-datatip-renderer/ http://help.adobe.com/en_ ...
- 20155217 2016-2017-2 《Java程序设计》第6周学习总结
20155217 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 第十章 InputStream与OutputStream 10.1.1串流设计的概念 Jav ...
- 20155224 实验一《Java开发环境的熟悉》实验报告
实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版) ...
- sql语句-8-sql学习流程
- rem布局注意问题和meta标签
使用rem前的准备: 如果是移动端,添加name="viewport"的meta标签,其中的属性数值根据实际需求而定: <meta name="viewport&q ...
- vcruntime140.dll 丢失64位系统
1. 下载VC Redistributable for VS2015,网址https://www.microsoft.com/en-us/download/confirmation.aspx?id=4 ...
- 解决循环里map不被重复覆盖的问题
参考:https://blog.csdn.net/zyf642112750/article/details/78295113 这样就不会一直重复 项目管理系统 了
- springmvc 使用 response 的注意事项以及解决500 空指针异常找不到 response 的方法
使用注解方式在类中(Controller)来装载request时,是可以正常使用request的(必须在启动时才注入,所以不支持热部署),但是同样使用这种方式在已经装载了 request的情况下装载 ...