1054 The Dominant Color (20 分)【难度: 简单 / 知识点: 思维】
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 分)【难度: 简单 / 知识点: 思维】相关推荐
- 【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 ...
- 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 ...
- 1054 The Dominant Color (20 分)_12行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Behind the scenes in the computer's memory, color is always talke ...
- 【PAT甲级 找到出现次数过半的数字】1054 The Dominant Color (20 分) C++
题目 思路 用数组模拟维护一个栈,栈内存储的数据有两个属性:数字.数量. 读取数字,如果数字已存在,相应位置上的数量+1 如果数字不存在,新建这个数字,size++,相应位置上的数量设置为1 题解 C ...
- 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:[C++题解]哈希表、水题
文章目录 题目分析 题目链接 题目分析 来源:acwing AC代码 #include<bits/stdc++.h> using namespace std; const int N = ...
- 13. 找出数组中重复的数字【难度: 简单 / 知识点: 模拟】
13. 找出数组中重复的数字[难度: 简单 / 知识点: 模拟] 方法一: map 计数 时间复杂度O(nlongn) 空间复杂度多了一个二叉树 class Solution {public:int ...
- 1132 Cut Integer (20 分)【难度: 简单 / 知识点: 模拟】
https://pintia.cn/problem-sets/994805342720868352/problems/994805347145859072 就是简单的模拟即可. #include< ...
- 1152 Google Recruitment (20 分)【难度: 简单 / 知识点: 模拟】
https://pintia.cn/problem-sets/994805342720868352/problems/1071785055080476672 #include<bits/stdc ...
最新文章
- [CLR via C#]5.3 值类型的装箱和拆箱
- php处理html5文件上传代码,HTML5中文件上传的代码
- SAP Data Intelligence Graph json源代码的结构分析
- windows7电脑删除文件特别慢怎么回事
- 数据结构与算法之-----图(搜索算法)
- 小孩看python_小朋友,python是否让你有很多问号?
- 新手教程:Mac电脑如何设置自动隐藏菜单栏?
- selenium: 网页打开最大化
- html 调试502谷歌浏览器,谷歌浏览器打不开网页提示Server Error 502 Bad Gateway怎么修复?...
- 辅材先生之打开传统向互联网+辅材这把锁
- javascript中mouseover和mouseout事件详解
- Win10鼠标右键添加CMD选项
- windwos操作系统有snmp服务器,windows服务器snmp v3
- 百度地图爬虫——小试牛刀
- 双向链表:P1996约瑟夫问题的解决方法
- HEVC代码学习——帧间预测:预测MV获取(xEstimateMvPredAMVP、fillMVPCand)
- VC++游戏编程----游戏画面特效制作1
- Bugzilla的使用
- 电脑免费录屏软件哪个好用?分享3款,亲测好用
- 从婚恋网站危机到6千亿元蛋糕