1054 The Dominant Color (20 分)_12行代码AC
立志用最少的代码做最高效的表达
PAT甲级最优题解——>传送门
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 24Sample Output:
24
散列表,永远滴神
流同步问题:
如果采用cin、cout输入输出,需要取消流同步,即:ios::sync_with_stdio(false);
。 速度相较于scanf、printf来说更快。
集合和映射问题:
储备知识扩展(很重要,提高效率,降低码量):
set——有序去重集合。
map——有序去重映射
multiset——有序不去重集合
multimap——有序不去重映射
unordered_set——无序不去重集合(普通集合)
unordered_map——无序不去重映射(普通映射)
#include<bits/stdc++.h>
using namespace std;
int main() {ios::sync_with_stdio(false);int n, m; cin >> n >> m;unordered_map<int, int>um;for(int i = 0; i < n*m; i++) {int x; cin >> x; um[x]++;if(um[x] >= (n*m)/2+1) { cout << x; return 0; }}return 0;
}
耗时:
求赞哦~ (✪ω✪)
1054 The Dominant Color (20 分)_12行代码AC相关推荐
- 【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 ...
- 1081 Rational Sum (20 分)_22行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given N rational numbers in the form numerator/denominator, you a ...
- 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 求平均值 (20分)_31行代码AC
立志用更少的代码做更高效的表达 Pat乙级最优化代码+题解+分析汇总-->传送门 本题的基本要求非常简单:给定 N 个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个" ...
- 1094 谷歌的招聘 (20分)_25行代码AC
立志用最少的代码做更高效的表达 PAT乙级最优题解-->传送门 2004 年 7 月,谷歌在硅谷的 101 号公路边竖立了一块巨大的广告牌(如下图)用于招聘.内容超级简单,就是一个以 .com ...
- 【测试点分析】1067 试密码 (20分)_20行代码AC
立志用更少的代码做更高效的表达 Pat乙级最优化代码+题解+分析汇总-->传送门 当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死.本题就请你实 ...
- 1073 多选题常见计分法 (20 分)_66行代码AC
立志用最少的代码做最高效的表达 PAT乙级最优题解-->传送门 批改多选题是比较麻烦的事情,有很多不同的计分方法.有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项, ...
最新文章
- em算法的java实现_EM算法 - Java教程 - 找一找教程网
- Appcan页面跳转
- 第十三章、facl及用户及Linux终端
- Java程序员面试中的多线程问题
- HDFS High Availability体系介绍(Using the Quorum Journal Manager)
- H.264的两个概念:DC系数和AC系数。 MV预测过程详解(附图)
- 定值保险计算举例_保险公司的“开门红”又要来了!理财险真的值得买吗?
- 我是小白0基础,现在我想学习前端开发,该如何系统的学习?
- 业绩上不去,老板和业务员都有责任,但首先要划分清楚责任
- 敏捷开发一千零一问系列之十:总体架构什么时机进行?(下)
- 不用PLC编程,实现USB或串口条码枪对接PLC,数据直接写入寄存器
- 微pe工具箱 系统安装教程_微pe工具箱怎么装系统
- 乐心健康php,《乐心健康》修改步数网页【获取方法】入口
- python 使用ThreadPool 创建线程,后台执行并check
- 2020 年,从架构谈起,到 Mesh 结束
- Java-Thread-Affinity框架使用及原理分析
- 中粮营销致远A6应用探秘:高速审批执行,营销策略落地
- nginx负载均衡 tomcat报异常: parseHost The host [*] is not valid
- 如何将多个excel表格合并成一个_如何把两个excel表合并成一个
- Cesium for UE4 4.27 demo实现代码