题目

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


题解

#include<iostream>
#include<map>
using namespace std;//1不在,加进去,计数/2直接用数组a[][]=次数
int main(){int m,n;scanf("%d %d",&m,&n);map<int,int> arr;int half=m*n/2;for(int i=0;i<n;i++){for(int j=0;j<m;j++){int num;//cin>>num;scanf("%d",&num);arr[num]++;//temp的次数加1if(arr[num]>half){printf("%d",num);return 0;}}}return 0;
}

本题主要是STL中Map的使用。
问题主要在于,被替换掉的注释部分,用cin则运行超时。至于为何还有待思考一下。

PAT甲级1054 map的使用相关推荐

  1. PAT甲级1054 The Dominant Color:[C++题解]哈希表、水题

    文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...

  2. PAT甲级1022 map、set的使用

    题目 A Digital Library contains millions of books, stored according to their titles, authors, key word ...

  3. PAT甲级1131 Subway Map (30分):[C++题解]堆优化dijkstra、单源最短路、地铁地图、巧妙地建图套dijkstra模板!!

    文章目录 题目分析 题目链接 题目分析 原题: 来源:acwing 分析: 建图:所有能走到的点之间建立一条边,比如下面一条地铁线路有4站,它们是相通的,两两之间建一条边,边权是经过的站点数. 下面考 ...

  4. PAT甲级1111 Online Map (30分):[C++题解]两次dijkstra求单源最短路、保存路径、长度最短、时间最短

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析:dijkstra求单源最短路的题目. 只是写两遍而已,第一遍求按照路径长度求,第二遍按照时间最少求. 另外加一个vector路径的判断 ...

  5. 【PAT甲级】字符串处理及进制转换专题

    目录 字符串处理 PAT甲级 1001 A+B Format (20 分) PAT甲级1005 Spell It Right (20 分) PAT甲级1035 Password (20 分) PAT甲 ...

  6. PAT甲级考试题库题目分类

    PAT甲级题目分类 水题 1136.1139.1143.1148 字符串处理 1001.1005.1035.1061.1073.1077.1082. 1108.1140.1152 模拟 1002.10 ...

  7. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

  8. PAT甲级训练合集(1-70)

    本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...

  9. PAT甲级1042~1055

    前言:距离四级考试剩23天,PAT甲级考试剩24天 对PAT甲级练习题做总结 1042 Shuffling Machine (20 分) 题目大意: 重复给出排列方式,把放在下标 i i i的牌调换到 ...

最新文章

  1. 大数据能力提升项目| 学生成果展系列之一
  2. angularjs与java_关于angularjs与java结合,获取后台数据并解析的问题
  3. bootstrap-内联文本元素-插入文本
  4. please get a license from www.texturepacker.com
  5. Teleport Pro使用教程
  6. 使用Python批量修改PPTX文件中文本框格式
  7. hql 查询关联对象_在spring data jpa中如何做报表统计查询?
  8. 1.5T和2.0L哪个好?
  9. 最新手机芯片AI跑分出炉:高通、联发科力压华为
  10. 服务不支持chkconfig
  11. Java 语法 索引 ----- 继承(Inheritance) 和重写(Overriding)
  12. 第一次作业+105032014140
  13. c语言如何输出结构体数组,怎么才能把结构体里面的二维数组打印出来?
  14. 射击比赛的成绩 华为od js
  15. 程序人生——苏嵌第三天
  16. android10(Q) API29下,通过getDeviceId()方法获取imei 报错的处理办法
  17. 小米5主板原理图_小米5手机拆机图解教程
  18. git之合并分支|git如何合并分支
  19. 数字经济的压舱石、国家安全的新维度 --《数据安全法(草案)》之解读
  20. 视频 | 新基建:模式与路径 - 黄奇帆 王建宙 巴曙松 凌克 吴明辉 周伯文

热门文章

  1. java遇到无穷大抛异常_Java中一个for语句导致无穷大死循环的例子
  2. deepin系统15.6版本安装执行那个exe文件_深度操作系统 deepin 20(1003)正式版发布:计算器支持科学计算,新增邮件、相机等应用...
  3. java 支持 shards 的jar_Solr Cloud:跨节点分配Shards
  4. oraclejobs_Oracle Scheduler Jobs
  5. Qt常用数据类型转换
  6. js获取验证码倒计时60s(超简单)
  7. 机器学习常见的六大错误
  8. Android 应用启动速度优化
  9. [ACM_数学] Fibonacci Nim(另类取石子,2-4组合游戏)
  10. (推荐)jQuery性能优化指南