码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【PAT(甲级)】1054 The Dominant Color


    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

    解题思路:

    题目给出N行,M列的颜色,要求你输出其中出现次数最多的颜色。又是一道数字与数字对应的题目,我们用map来存储每个数字出现的次数,再通过循环找到出现次数最多的即可。

    代码:

    1. #include
    2. using namespace std;
    3. int main(){
    4. int M,N;
    5. cin>>M>>N;
    6. map<int,int> color;//存储每种颜色出现的次数
    7. for(int i=0;i
    8. for(int j=0;j
    9. int t;
    10. cin>>t;
    11. color[t]++;
    12. }
    13. }
    14. auto tip = color.begin();//默认下标指向一开始输入的颜色
    15. int max = tip->second;//用来存储颜色出现最多的次数
    16. for(auto i = color.begin();i!=color.end();i++){
    17. if(i->second>max){
    18. tip = i;//如果出现次数最多,则替换
    19. max = i->second;
    20. }
    21. }
    22. cout<first;
    23. return 0;
    24. }

  • 相关阅读:
    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
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号