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.
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.
For each test case, simply print the dominant color in a line.
5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
24
题目给出N行,M列的颜色,要求你输出其中出现次数最多的颜色。又是一道数字与数字对应的题目,我们用map
- #include
- using namespace std;
- int main(){
- int M,N;
- cin>>M>>N;
- map<int,int> color;//存储每种颜色出现的次数
-
- for(int i=0;i
- for(int j=0;j
- int t;
- cin>>t;
- color[t]++;
- }
- }
-
- auto tip = color.begin();//默认下标指向一开始输入的颜色
- int max = tip->second;//用来存储颜色出现最多的次数
- for(auto i = color.begin();i!=color.end();i++){
- if(i->second>max){
- tip = i;//如果出现次数最多,则替换
- max = i->second;
- }
- }
- cout<
first; -
- return 0;
- }
-
相关阅读:
Python函数 - - reverse()和reversed()
Win10 开机突然不断重复诊断和自动修复,安全模式也进不了,如何解决?(已解决)
Codeforces Round #814 (Div. 2)
Qt无边框设计
python(爬虫篇)——Xpath提取网页数据
使用任务定时执行软件的定时关机功能,控制电脑可用时间段
paddle 41 在paddledetection添加RotateScaleCopyPaste数据增强方法
flutter开发实战-inappwebview实现flutter与Javascript方法调用
《爆肝整理》保姆级系列教程-玩转Charles抓包神器教程(10)-Charles如何修改请求参数和响应数据-下篇
Zotero(3)---使用茉莉花插件提取中文文献信息
-
原文地址:https://blog.csdn.net/weixin_55202895/article/details/126611744