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 ...
随机推荐
- Linux文本三剑客
grep 文本过滤工具. 作用: 文本搜索工具,根据用户指定的行进行匹配检查,打印匹配到的行. 模式: 由正则表达式字符及文本字符所编写的过滤条件. grep的使用 语法: grep [OPTION ...
- sed知识及常用用法梳理
1.sed命令简介及其参数说明 sed流编辑器,擅长对文本进行增删改查,过滤指定的字符串和取指定行,也可以在行中字符串前后插入内容,功能非常强大. 注意:sed默认只支持基本的正则表达式,如果要想支持 ...
- python2 + Django 中文传到模板页面变Unicode乱码问题
1.确保views页面首行设置了默认编码 # -*-coding:utf-8 -*- 2.确保html页面的编码为 utf-8 3.确保项目setting文件设置了 LANGUAGE_CODE = ...
- 网络模块axios的简单应用
一.axios的基本使用 例子中使用到的url仅作为示例,不一定有效,想要复现代码需要使用能够提供数据的有效服务器接口url 1.1.什么是axios axios:ajax i/o system:是用 ...
- Docker深入浅出系列 | 容器数据持久化
Docker深入浅出系列 | 容器数据持久化 Docker已经上市很多年,不是什么新鲜事物了,很多企业或者开发同学以前也不多不少有所接触,但是有实操经验的人不多,本系列教程主要偏重实战,尽量讲干货,会 ...
- go每日新闻--2020-02-27
go 语言中文网(每日资讯)_2020-02-27 一.Go 语言中文网 如何正确看待 Google 宣布 Fuchsia 操作系统没有选 Go 作为终端开发语言 Actor 还是 CSP?Go 中的 ...
- CSS权威指南(第三版)
CSS权威指南(第三版).pdf 网盘: https://545c.com/file/24657411-425141851 获取码: 276922
- nginx 修改上传文件的大小限制
nginx默认的上传文件大小是有限制的,一般为2MB,如果你要上传的文件超出了这个值,将可能上传失败.修改的地方有: 1. php.ini: upload_max_filesize = 8M 2. ...
- Appium超详细环境搭建for Mac
兜兜转转试用了一圈自动化框架后,回归到appium,与一年之前相比,appium有了很大的改变:1.iOS 9 之前一直以 instruments 下的 UIAutomation为驱动底层技术(弊 ...
- 抽取vs2010安装包中vc++ runtime
写于2015-3-21 16:59 由qq空间转过来,格式有点乱 之前遇到一个问题,c++\cli的程序部署在服务器上面,程序运行后没有反应就退出了,日志管理器中记录两个错误信息分别如下: ...