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,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
解题思路:
简单使用数组的话会超内存,要用map映射。
#include<cstdio>
#include<map>
using namespace std;
int main(){int n,m,ans,temp;map<int,int>mp;scanf("%d%d",&m,&n);for(int i=0;i<n;i++){for(int j=0;j<m;j++){scanf("%d",&temp);if(mp.find(temp)!=mp.end() ) mp[temp]++;else mp[temp]=1;if(mp[temp]*2>n*m) ans=temp;}}printf("%d",ans);return 0;
}
1054 The Dominant Color(20 分)相关推荐
- 【PAT (Advanced Level) Practice】1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- PAT_(STL使用)map-1100 Mars Numbers (20分)-1054 The Dominant Color (20分)-1071-1022
目录 1100 Mars Numbers (20分) 1054 The Dominant Color (20分) 1071 Speech Patterns (25分) 1022 Digital Lib ...
- 1054 The Dominant Color (20 分)_12行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Behind the scenes in the computer's memory, color is always talke ...
- 1054 The Dominant Color (20 分)【难度: 简单 / 知识点: 思维】
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 因为数量多于一半,故排序后中间必为答案. # ...
- 【PAT甲级 找到出现次数过半的数字】1054 The Dominant Color (20 分) C++
题目 思路 用数组模拟维护一个栈,栈内存储的数据有两个属性:数字.数量. 读取数字,如果数字已存在,相应位置上的数量+1 如果数字不存在,新建这个数字,size++,相应位置上的数量设置为1 题解 C ...
- 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:[C++题解]哈希表、水题
文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...
- 1054 The Dominant Color
1. 此题用到了map<string,int>将输入的颜色(long long也存不下,只好作为string存入)的次数记录,看来默认一个没出现过的string对应的int是0.因此记次数 ...
- PTA 1054 求平均值 (20 分)
文章目录 code1 18分 code2 20分 注意点 code1 18分 #include<iostream> #include<string.h> using names ...
- C++学习之路 | PTA乙级—— 1068 万绿丛中一点红 (20 分)(精简)
1068 万绿丛中一点红 (20 分) 对于计算机而言,颜色不过是像素点对应的一个 24 位的数值.现给定一幅分辨率为 M×N 的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点 ...
最新文章
- c++ 调用labview_LabVIEW面向对象编程_初窥门径(5):开发方式漫谈
- 百度Apollo发布中国首个自动驾驶安全报告,L3级别产品2020年量产上市
- linux 挂载 nfs 权限,linux – 如何允许写入已挂载的NFS分区
- php中用foreach改变数组的值的问题
- JAVA中的常量定义在class中还是interface中比较合理?
- 4kyu Twice linear
- javaWeb服务详解(含源代码,测试通过,注释) ——web.xml
- QT-lesson1-无边框窗口创建/拖拽/阴影-20190322
- win11错误代码0xc1900101怎么解决 windows11错误代码0xc1900101的解决方法
- 防爆技术在工业电子秤中的最新应用(转)
- Python移动应用开发
- pdf怎么解除限制?如何解密?一步解决
- sqlite中的 database is locked 问题
- 【云原生】内存数据库如何发挥内存优势
- one algorithm a day keeps the doctor away -- BubbleSort
- 微软跟投,估值31.5亿美元的光量子计算公司刚刚完成4.5亿美元融资
- Windows 安装Docker碰到 cannot enable hyper-v service
- 360奇舞团钟恒:选用Vue.js进行组件化开发,我们遇到了哪些坑?
- VM 虚拟机屏幕大小的调整
- 四川大学图书情报档案专业考研经验贴(2022.9.16已更新)
热门文章
- 关于铁路订票系统如何改善设计的讨论
- 关于HTML学习的第一周周记
- 全国计算机第55次,全国第55次一级Ms Office试题
- Java多线程系列--【JUC集合07】- ArrayBlockingQueue
- 数据增强:模拟雨天算法Python
- c语言题库字母顺序,C语言题库(带答案)-排版-
- 谁谋杀了我们的游戏?转自 斗战神制作人-Yocar
- android+背景虚化,android背景虚化
- 理解 this.initialize.apply ( this, arguments )
- python中英文古风排版_古风排版 - Calculus9 - 博客园