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 ...
随机推荐
- coroutine - yield from
yield from yield from x 表达式对 x 对象所做的第一件事是,调用 iter(x),从中获取迭代器.因 此, x 可以是任何可迭代的对象. 可是,如果 yield from 结构 ...
- 集智学院 “Deep X:Deep Learning with Deep Knowledge”的公开讲座---总结
人工智能旨在了解人类智能的本质,并创造出能模仿人类智能做出反应的智能机器,目前在一些领域已经取得显著的成功,如AI玩游戏.问答系统.自动驾驶.无人机.机器人.翻译.人脸识别.语音识别等领域.深度学习的 ...
- [Linux]命令返回值以及错误对照表
Linux执行完命令之后默认会有一个返回值 # ls app backupconfig.json Doc manage.py __pycache__ settings.py # echo $? 0 错 ...
- python pandas合并多个excel(xls和xlsx)文件(弹窗选择文件夹和保存文件)
# python pandas合并多个excel(xls和xlsx)文件(弹窗选择文件夹和保存文件) import tkinter as tk from tkinter import filedial ...
- Webpack中hash、chunkhash和contenthash三者的区别
在webpack中有三种的方式生成哈希值,分别为hash.chunkhash和contenthash.这三种方式有着不同的用处,或者说在webpack的不同环境中,会使用不同的方式生成哈希值.那为什么 ...
- JVM类加载器是否可以加载自定义的String
前言 曾经有一次,面试官问到类加载机制,相信大多数小伙伴都可以答上来双亲委派机制,也都知道JVM出于安全性的考虑,全限定类名相同的String是不能被加载的.但是如果加载了,会出现什么样的结果呢?异常 ...
- 使用Visual Studio Comunity 2019开发Unity C#脚本没有自动补全的解决方法
最近开始试着玩Unity3D,要为场景中的物体编辑脚本.Unity3D推荐的脚本语言是C#,在Unity打开C#就会使用Visual Studio来进行编辑. 启动Visual Studio之后注意到 ...
- .net core 轻量级容器 ServiceProvider 源码分析
首先看 ServiceCollection 的定义 //定义 public class ServiceCollection : IServiceCollection { private readonl ...
- 解决.net core3.1使用docker部署在Ubuntu上连接sqlserver报error:35的问题
最近把一个项目从core2.2迁移至core3.1,在本地win上跑没有问题,但是上线到生产Ubuntu docker环境下连接不上sqlserver报以下错误. A connection was s ...
- Redis 为什么这么快?
1. 纯内存操作,肯定快 数据存储在内存中,读取的时候不需要进行磁盘的 IO 2. 单线程,无锁竞争损耗 单线程保证了系统没有线程的上下文切换 使用单线程,可以避免不必要的上下文切换和竞争条件,没有多 ...