https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768
因为数量多于一半,故排序后中间必为答案。

#include<bits/stdc++.h>
using namespace std;
const int N=1010;
int x,n,m;
vector<int>ans;
int main(void
{cin>>m>>n;for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>x,ans.push_back(x);sort(ans.begin(),ans.end());cout<<ans[ans.size()/2];return 0;
}

摩尔投票法

#include<bits/stdc++.h>
using namespace std;
int x,n,m;
stack<int>st;
int main(void)
{cin>>m>>n;for(int i=0;i<n;i++)for(int j=0;j<m;j++){int x; cin>>x;if(st.empty()) st.push(x);else if(st.top()!=x) st.pop();else if(st.top()==x) st.push(x);}cout<<st.top();return 0;
}

1054 The Dominant Color (20 分)【难度: 简单 / 知识点: 思维】相关推荐

  1. 【PAT (Advanced Level) Practice】1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  2. PAT_(STL使用)map-1100 Mars Numbers (20分)-1054 The Dominant Color (20分)-1071-1022

    目录 1100 Mars Numbers (20分) 1054 The Dominant Color (20分) 1071 Speech Patterns (25分) 1022 Digital Lib ...

  3. 1054 The Dominant Color (20 分)_12行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Behind the scenes in the computer's memory, color is always talke ...

  4. 【PAT甲级 找到出现次数过半的数字】1054 The Dominant Color (20 分) C++

    题目 思路 用数组模拟维护一个栈,栈内存储的数据有两个属性:数字.数量. 读取数字,如果数字已存在,相应位置上的数量+1 如果数字不存在,新建这个数字,size++,相应位置上的数量设置为1 题解 C ...

  5. 1054. The Dominant Color (20)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...

  6. PAT甲级1054 The Dominant Color:[C++题解]哈希表、水题

    文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...

  7. 13. 找出数组中重复的数字【难度: 简单 / 知识点: 模拟】

    13. 找出数组中重复的数字[难度: 简单 / 知识点: 模拟] 方法一: map 计数 时间复杂度O(nlongn) 空间复杂度多了一个二叉树 class Solution {public:int ...

  8. 1132 Cut Integer (20 分)【难度: 简单 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 就是简单的模拟即可. #include< ...

  9. 1152 Google Recruitment (20 分)【难度: 简单 / 知识点: 模拟】

    https://pintia.cn/problem-sets/994805342720868352/problems/1071785055080476672 #include<bits/stdc ...

最新文章

  1. [CLR via C#]5.3 值类型的装箱和拆箱
  2. php处理html5文件上传代码,HTML5中文件上传的代码
  3. SAP Data Intelligence Graph json源代码的结构分析
  4. windows7电脑删除文件特别慢怎么回事
  5. 数据结构与算法之-----图(搜索算法)
  6. 小孩看python_小朋友,python是否让你有很多问号?
  7. 新手教程:Mac电脑如何设置自动隐藏菜单栏?
  8. selenium: 网页打开最大化
  9. html 调试502谷歌浏览器,谷歌浏览器打不开网页提示Server Error 502 Bad Gateway怎么修复?...
  10. 辅材先生之打开传统向互联网+辅材这把锁
  11. javascript中mouseover和mouseout事件详解
  12. Win10鼠标右键添加CMD选项
  13. windwos操作系统有snmp服务器,windows服务器snmp v3
  14. 百度地图爬虫——小试牛刀
  15. 双向链表:P1996约瑟夫问题的解决方法
  16. HEVC代码学习——帧间预测:预测MV获取(xEstimateMvPredAMVP、fillMVPCand)
  17. VC++游戏编程----游戏画面特效制作1
  18. Bugzilla的使用
  19. 电脑免费录屏软件哪个好用?分享3款,亲测好用
  20. 从婚恋网站危机到6千亿元蛋糕

热门文章

  1. 方差过滤: Removing features with low variance
  2. HDFS的读文件、写文件过程
  3. Jenkins构建自动化脚本执行无界面解决方法
  4. linux命令:ftp
  5. HDU1020 Encoding
  6. POJ2301+水~~~~~~
  7. 读者看《赢道:成功创业者的28条戒律》
  8. nRF52832 — 连接指定name、UUID、addr的蓝牙设备
  9. 【ESP8266】NONOS SDK开发,发送HTTP请求
  10. Mosquitto配置----日志设置