当前位置:网站首页>Pat 1054 the dominiant color (20 points)
Pat 1054 the dominiant color (20 points)
2022-06-28 21:57:00 【Python ml】
408 Optimal solution Spatial complexity O(1)
#include <iostream>
using namespace std;
int main() {
long long temp,major=-1;
int m,n,cnt=0;
cin>>m>>n;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>temp;
if(temp!=major){
cnt--;
if(cnt<=0){
major=temp;
cnt=1;
}
}else cnt++;
}
}
cout<<major;
return 0;
}
STL in map The answer is ⽤~ send ⽤arr[i] = j Express i The element appears in the matrix j Time , Losing ⼊ At the same time ⽐ a arr The current value
Whether more than half , If exceeded , Just output the number and exit the program
#include <iostream>
#include <map>
using namespace std;
int main() {
int m, n;
scanf("%d %d", &m, &n);
map<int, int> arr;
int half = m * n / 2;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
int temp;
scanf("%d", &temp);
arr[temp]++;
if(arr[temp] > half) {
printf("%d", temp);
return 0;
}
}
}
return 0;
}
边栏推荐
- Is it safe to open a stock trading account? Is it reliable?
- LeetCode213. House raiding II
- 河狸生存记:90后女博士与AI开发者们
- How do independent site sellers efficiently manage complex Facebook pages?
- How to open a safe and reliable securities account in the financial management class of qiniu school?
- Interface test process
- be careful! The PMP emergency postponement exam is due today!
- Understanding of incomplete types
- Lumiprobe protein labeling research scheme
- LeetCode121. The best time to buy and sell stocks
猜你喜欢

The rogue downloader named by 315 is back

Study on luminiprobe non fluorescent azide -- 3-azido propanol

Mongodb - replica set and sharding

BOE was brilliant for the Winter Olympics, but revealed another Chinese technology enterprise dominating the world

接口测试流程

Microsoft's exclusive payment function has also been perfectly unlocked

AI deep dive of Huawei cloud
![Sword finger offer:[day 2 linked list (simple)] --- > reverse linked list](/img/05/0d7ed95f83c2188d274dde84817dc3.jpg)
Sword finger offer:[day 2 linked list (simple)] --- > reverse linked list

What is an interface? What is interface testing?

Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!
随机推荐
How to make up the PMP Exam? How much is the make-up exam?
CORBA Architecture Guide (Common Object Request Broker Architecture)
[linq]c list type grouping sum
17 `bs对象.节点名h3.parent` parents 获取父节点 祖先节点
Sword finger offer:[day 1 stack and queue (simple)] --- > stack containing min function
炒股票能赚钱么?开户安全嘛
LeetCode188. The best time to buy and sell stocks IV
Real time transformer: meituan's research on single image depth estimation
Un voyage profond d'IA dans Huawei Cloud
To be a cross-border e-commerce, you must learn to use PRA software, free your hands and improve efficiency!
How do independent site sellers efficiently manage complex Facebook pages?
Understanding web automated testing
[webapi] return dynamic list dynamic
Construction and application of urban brain knowledge map
精通数据分析能力,收入翻倍?什么才是最强竞争力
LeetCode122. 买卖股票的最佳时机II
Lumiprobe protein labeling research scheme
Postman introduction and installation steps
构建实战化防御体系之立体防渗透
Ehcache configuration data, convenient for self checking