1054 The Dominant Color (20)(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, 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, 2^24^). 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
#include<cstdio>
int main(){
int m,n,col,ans= -,count = ;
scanf("%d%d",&m,&n);
for(int i = ; i < m; i++){
for(int i = ; i < n; i++){
scanf("%d",&col);
if(count == ){
ans = col;
count = ;
}
else{
if(ans == col) count++;
else count--;
}
}
}
printf("%d",ans);
return ;
}
#include<cstdio>
#include<map>
using namespace std;
int main(){
int n,m,col;
map<int,int> count;
scanf("%d%d",&m,&n);
for(int i = ; i < m; i++){
for(int j= ; j < n; j++){
scanf("%d",&col);
if(count.find(col)!=count.end()) count[col]++;
else count[col] = ;
}
}
int k = , max = ;
for(map<int,int>::iterator it=count.begin(); it != count.end(); it++){
if(it -> second > max){
k = it -> first;
max = it -> second;
}
}
printf("%d",k);
return ;
}
1054 The Dominant Color (20)(20 分)的更多相关文章
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- pat 1054 The Dominant Color(20 分)
1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked abo ...
- PAT 1054 The Dominant Color
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- PAT 甲级 1054 The Dominant Color (20 分)(简单题)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- PAT 1054 The Dominant Color[简单][运行超时的问题]
1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...
- 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 i ...
- 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 i ...
- 1054. The Dominant Color (20)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...
- PAT 甲级 1054 The Dominant Color
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 Behind the scenes in t ...
随机推荐
- MQ相关
1. 如何保证消息按顺序执行 2. 如何保证消息不重复消费 3. 如何保证消息不丢失 4.RabbitMQ Java Client简单生产者.消费者代码示例
- IOS - 总结下swift使用GCD 多线程(二)GCD和DispatchQueue
1.前言 iOS中处理多核并发的技术有两种分别是:`Grand Central Dispatch`(以下简称`GCD`)和`NSOperationQueue`框架.iOS开发的老司机们在程序开发中处 ...
- 纯CSS一个div实现无缝隙尖角框
话不多说直接先上效果图 其实原理很简单,就是一个带边框的方块加上一个黑色三角形和一个白色三角形,最后通过position定位实现. 代码如下: HTML就一个div <div></d ...
- 阿里云ssl协议发布qq邮件
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx. ...
- Air for ANE:打包注意的地方
来源:http://blog.csdn.net/hero82748274/article/details/8631982 今天遇到了一个打包ANE 文件的问题,导致花费了几个小时查找,最后师弟的一句话 ...
- Redis除了做缓存--Redis做消息队列/Redis做分布式锁/Redis做接口限流
1.用Redis实现消息队列 用命令lpush入队,rpop出队 Long size = jedis.lpush("QueueName", message);//返回存放的数据条数 ...
- 获取项目中所有URL--获取swagger上展示的接口信息
有时我们需要接口的一些基本信息,比如接口请求路径,接口请求方式等,我们用这些信息来做判断,或者入库. 我在开发接口权限的时候就遇到了这个问题,之前写的接口很多,现在需要将这些接口信息存到数据库中, 用 ...
- idea中添加web.xml配置文件与tomcat启动中遇到的web.xml文件找不到的问题
1,如何在idea中向war项目中添加web.xml的配置文件 idea通过maven创建war项目时没有指定是webapp导致创建出来的项目没有webapp的文件夹.其实war项目中都是在" ...
- [dev][nginx] 在阅读nginx代码之前都需要准备什么
前言 以前,我读过nginx的源码,甚至还改过.但是,现在回想起来几乎回想不起任何东西, 只记得到处都是回调和异步,我的vim+ctags索引起来十分吃力. 几乎没有任何收获,都是因为当时打开代码就看 ...
- 使用fail2ban预防被挖洞的笔记
参考:https://blog.csdn.net/dorisnzy/article/details/82926067 1.安装fail2ban: yum -y install epel-release ...