1054. The Dominant Color (20)

时间限制
100 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard

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, 800x600), 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, 224). 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

通过查找,每次从列表中除去两个不一样的数,最后就可以得出这个数,时间复杂度O(N)。写法上也有技巧,不必非要找到一个不一样的在继续下去,如果下一个一样,那么用一个变量记录这个次数,把次数+1,遇见不一样的-1。例如1,1,2,3,4 初始value =1,count =1,第二个1,value = 1,count =2,下一个2,value=1,count=1,下一个3,value=3,count=0,下一个4,value=4,count=1...一直到最后,看下value的值,就是所要找的数。

#include"iostream"
#include "algorithm"
#include <string>
#include "cstring"
#include"sstream"
using namespace std;

int main()
{
int m,n;
scanf("%d%d",&m,&n);

int Times=0,value;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{
int num;
scanf("%d",&num);//用cin会超时
if(Times ==0)
{
value = num;
Times++;
}
else
{
if(num == value)
Times++;
else
Times--;
}

}
printf("%d\n",value);

return 0;
}

浙大pat 1054 题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  8. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. 浙大pat 1059 题解

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

随机推荐

  1. unity3d使用litjson中文显示的问题

    我们在使用litjson时它的编码方式是unicode的,所以我将json转成string输出时显示的是unicode的编码.这样我们显示或者保存中文时不是很方便.我们可以将中文的unicode转成能 ...

  2. 详细介绍Java垃圾回收机制

    垃圾收集GC(Garbage Collection)是Java语言的核心技术之一,之前我们曾专门探讨过Java 7新增的垃圾回收器G1的新特性,但在JVM的内部运行机制上看,Java的垃圾回收原理与机 ...

  3. Xcode使用小结2

    刷新时间慢的时候用timer定时器 以下内容为借用,作者:FlyElephant出处:http://www.cnblogs.com/xiaofeixiang iOS开发-NSOperation与GCD ...

  4. Python学习笔记——基础篇1【第三周】——set集合

    set集合 不允许重复的元素出现(相当于特殊的列表) set 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 练习:寻找差异 # 数据库中原有 old_dic ...

  5. c# 操作xml之xmlReader

    xmlReader的名称空间using System.Xml; xmlReader是通过流的方式来读取xml文件的内容 <?xml version="1.0" encodin ...

  6. 《Intel汇编第5版》 条件汇编伪指令

    一.条件汇编伪指令和宏使用可以使汇编程序更加灵活 二.通过伪指令来检查函数的参数是否为空,如果为空则输出警告信息 INCLUDE Irvine32.inc includelib Irvine32.li ...

  7. 用ftplib爆破FTP口令

    #coding:utf-8 #author:jwong import ftplib def bruteLogin(hostname,passwordFile): with open(passwordF ...

  8. shell获取系统时间

    获取系统时间 date -d"yesterday" +"%F %H:%M:%S" #输出昨天这个时候的时间 date -d"tomorrow" ...

  9. 如何使用Maven的archetype快速生成一个新项目(解决生成项目目录不完整问题)

    Maven的archetype Plugin可能大家都听过,但不一定都能很好地用好它.缺省地如果你使用 mvn archetype:generate  会从maven的Repository里查找所有支 ...

  10. xcode常见错误

    ------------------------------------------错误列表----------------------------------------------   1.Ter ...