PAT (Advanced Level) Practice 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, 8), 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 (≤) and N (≤) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0). 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
思路:初始化tmp为0,cnt为0,每次输入一个数与tmp比较如果相同cnt++,否则更新tmp值,因为题意是所求的值总会超过一半数据,所以最后留下来的tmp一定就是目标值。
#include <stdio.h>
int n,m;
int a[][];
int main()
{
scanf("%d %d",&m,&n);
int tmp=,cnt=;
for(int i=;i<n;i++){
for(int j=;j<m;j++){
scanf("%d",&a[i][j]);
if(a[i][j]==tmp){
cnt++;
}else{
tmp=a[i][j];
cnt=;
}
}
}
printf("%d\n",tmp);
return ;
}
PAT (Advanced Level) Practice 1054 The Dominant Color (20 分)的更多相关文章
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) (找最值)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
随机推荐
- eclipse里新建work set,将项目分组放在不同文件夹
想必大家的Eclipse里也会有这么多得工程...... 每次工作使用到的项目肯定不会太多...... 每次从这么大数量的工程当中找到自己要使用的, 必须大规模的滚动滚动条......有点不和谐了. ...
- linux命令之---ping
1)命令简介 ping命令用来测试主机之间网络的连通性.执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息,因而得知该主机运作正常. 2)命令参数 ...
- VFP 用 SPT 来发布一条 SELECT 到一个新的 SQL Server 表
为了发布一条 SQL SELECT 语句来创建一个新的 SQL Server 表, SQL Server 数据库的 select into/bulkcopy 选项必须是可用的. 在默认情况下, 对于 ...
- pytorch --Rnn语言模型(LSTM,BiLSTM) -- 《Recurrent neural network based language model》
论文通过实现RNN来完成了文本分类. 论文地址:88888888 模型结构图: 原理自行参考论文,code and comment: # -*- coding: utf-8 -*- # @time : ...
- (转载)Linux平台下安装 python 模块包
https://blog.csdn.net/aiwangtingyun/article/details/79121145 一.安装Python Windows平台下: 进入Python官网下载页面下载 ...
- 利用十字链表存储树结构(便于同时求出某一点的入度与出度)------C语言实现
#include <stdio.h> #include<conio.h> #include<stdlib.h> /* 利用十字链表存储有向图,可用于同时查找某个顶点 ...
- mac item2的快捷键
https://juejin.im/entry/58fac23fb123db4449071c99 听说这个工具可以解决,iterm2的整句翻译的问题.一致找不到免费的破解版本. Myna for Go ...
- codewars--js--Range Extraction
问题描述: A format for expressing an ordered list of integers is to use a comma separated list of either ...
- 1.3.6 详解build.gradle文件——Android第一行代码(第二版)笔记
不同于Eclipse,Android Studio是采用Gradle来构建项目的.Gradle是一个非常先进的项目构建工具,它使用了一种基于Groovy的领域特定语言(DSL)来声明项目设置. 首先看 ...
- MyBatis XML配置properties
来源:https://www.w3cschool.cn/mybatis/7zy61ilv.html XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(sett ...