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 分)的更多相关文章

  1. 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 ...

  2. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Linux下安装 php imagick扩展

    今天小编 由于工作需求用到了 imagick 这个扩展  服务器环境是 lnmp 架构下面稍微来介绍下 这个 东东 imagick是一个PHP的扩展,用ImageMagick提供的API来进行图片的创 ...

  2. sublime笔记

    插件安装和使用 首先,要安装package control,按照官方方法安装: https://packagecontrol.io/installation 重启Sublime Text 3. 如果在 ...

  3. div中元素水平居中的方法

    使用align属性 <div class="main" align="center">        <h1>MAIN</h1&g ...

  4. 处理jquery 中 给disabled属性不传值的问题

    问题:审核页面加入不可编辑的判断后,点击[审核]按钮,报错,form表单的数据没有传递过去. 下面是js中加入的代码,用来判断是否是审核页面的,去掉此代码,点击[审核]按钮能正常传递数据,加入的话,无 ...

  5. bootstrap-daterangepicker

    1,依赖关系 使用之前需要引用bootstrap.css   daterangpicker.css    jquery.js   boostrap.js  moment.js   daterangpi ...

  6. Objective-C编程 — 并行编程

    多线程 线程的基本概念 线程 (thread)是进程(process)A 内假想的持有 CPU 使用权的执行单位.一般情况下,一个进程 只有一个线程,但也可以创建多个线程并在进程中并行执行.应用在执行 ...

  7. Linux文件结构-底层文件访问&文件目录和维护

    每个运行中的程序被称为进程(process),它有一些与之关联的文件描述符(一些小值整数).可以通过文件描述符访问打开的文件或设备. 一个程序运行时,一般会有三个文件描述符与之对应 0:标准输入 1: ...

  8. 代理模式-jdk动态代理

    IDB package com.bjpowernode.proxy; /** * 代理类和目标类都必须使用同一个接口. */ public interface IDB { int insert(); ...

  9. 浅谈centos8与centos7

    距离centos8.0(现在已经更新到8.1了)的发布已经过去几个月了,作为一个刚刚接触过几个月centos的萌新来说,本文想通过实际的操作体验来说对比一下centos8代与7代 首先,centos8 ...

  10. Sercet sharing

    Secret Sharing Shamir门限 条件: \(0<k\leq n<p\) \(S<p,p\)是素数 Lagrange插值公式 \[ f(x)=\sum^{k}_{j=1 ...