当前位置:网站首页>1054 The Dominant Color
1054 The Dominant Color
2022-07-20 22:36:00 【Brosto_ Cloud】
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
Use map Container count .
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<string, int>p;
int main() {
int m, n;
string x;
cin >> m >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> x;
p[x]++;
}
}
for (map<string, int>::iterator it = p.begin(); it != p.end(); it++) {
if (it->second > (m * n / 2)) {
cout << it->first;
break;
}
}
return 0;
}
边栏推荐
- 如何用Redis实现消息的发布和订阅?实现原理又是什么?
- 基于STM32HAL库ADS1256调试笔记
- Debezium系列之:show slave status查看主从延迟可能存在的不同情形
- Implementation of fruit and vegetable mall management system based on SSM
- leetcode:460. LFU最不常用缓存
- Knowledge points of common interview questions: distributed lock
- Explain "onion architecture" in detail
- Google Earth Engine——如何通过函数返回值获取字符串中想获取的信息
- FileUploadBase$SizeLimitExceededException
- 同源策略,面经
猜你喜欢
7-15 operation
常见面试题知识点之:分布式锁
“先导杯”来啦!召唤科学计算界的最强大脑,36万奖池等你来拿!
Google Earth Engine——如何通过函数返回值获取字符串中想获取的信息
2022年北京产品经理认证招生简章(NPDP)
Modbus Poll/Slave 模拟器使用教程
Summary of SQL skills in data warehouse development
RoleApp聚焦Web3,用“数据可持有”的钥匙开启Web3的大门
API interface for adding and deleting videos in easydss platform customization project of internet live broadcast on demand
DOM事件流
随机推荐
连接无限·协同无界|融云首届全球企业通信云大会 WECC 来了
Full horizontal evaluation of mainstream timed task solutions
cookie如何测试
网上炒股开户真的安全吗?
吴恩达的机器学习,属实牛逼
Explain "onion architecture" in detail
华为无线设备配置不同业务VLAN的AP间非快速漫游
Deep decryption of go language context
Modbus Poll/Slave 模拟器使用教程
MATLAB篇之层次分析法
从wolai转移到Notion
Debezium系列之:show slave status查看主从延迟可能存在的不同情形
Design of the multi live architecture in different places of the king glory mall
西门子S7 模拟器使用教程
XML to VOC, VOC to coco, coco to Yolo, coco partition, coco check, Yolo check, coco visualization
阻力很大的舵机电流特性
你真的了解图像吗?(机器视觉)
EMQ映云科技成功入选《中国企业家》2022年度「新锐100」榜单
RoleApp聚焦Web3,用“数据可持有”的钥匙开启Web3的大门
MySQL deadlock, lock timeout, slow SQL summary