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 ...
随机推荐
- UnityShader - 渲染管线
定义: 显卡内部处理图像信号的并行处理单元,也称为渲染流水线 发生位置: CPU和GPU 渲染机理: 将图像所具备的图形信息(顶点.纹理.材质.摄像机位置等)经过一系列阶段的处理,最终转换为屏幕上的图 ...
- C# Java的加密的各种折腾
24位加密 Java public class DESUtil { private static final String KEY_ALGORITHM = "DESede"; pr ...
- Ubuntu linux安装完成后隐藏linux磁盘挂载点
方案1 打开注册表 , 找到这个位置: 计算机\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explore ...
- 安装Windows 2008 操作系统时加载ServeRAID-MR10系列阵列卡驱动
安装Windows 2008 操作系统时加载ServeRAID-MR10系列阵列卡驱动 适用机型: 所有System x3200 M2; 所有System x3250 M2; 所有System x33 ...
- C# 利用特性(Attribute)实现通用实体类数据合法校验
用过asp.net mvc 的都应该知道,在实体类上添加一些特性,可以实现后端实体的数据校验,这里简单实现一下 实现原理:利用反射获取实体的每一个属性,并通过属性获取属性上标注的特性,调用特性的Val ...
- sqlserver添加列(字段)描述
1.我的表 [id],[name],[type],[date]四个字段,,,表名是library 2.添加列描述 姓名:描述信息 library:表名 被描述字段:name EXECUTE sp_ad ...
- Centos部署项目
nginx + virtualenv + uwsgi + django + mysql + supervisor 部署项目 一.安装Python3 二.安装MariaDB,并授权远程 grant al ...
- springboot 使用常用注解
找到方法封装成json格式 @RestController = @Controller+@ResponseBody //一个组合注解,用于快捷配置启动类,springboot启动主入口 @Spring ...
- MongoDB的关闭
关闭 1,非后台运行时,关闭对话,或者ctrl+c 2,登录数据库执行:db.shutdownServer(); 3,带数据目录,关闭服务器,安全 mongod --shutdown --dbpa ...
- 爬虫(二)-创建项目&应用
一.回顾 上篇已经讲解了python-django的环境搭建,本次将继续上次的课程,开始创建项目及应用. 上篇的验证结果为: 本次将加上创建应用之后浏览器打开演示~ 二.创建项目 1)使用django ...