当前位置:网站首页>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;
}
边栏推荐
- Study on bifunctional crosslinker lumiprobe sulfoacyanine 7 dicarboxylic acid
- An artifact extracted from a well-known software and paid by a group of people
- 运动App如何实现端侧后台保活,让运动记录更完整?
- Recommend two high-quality Wallpaper software
- be careful! The PMP emergency postponement exam is due today!
- Un voyage profond d'IA dans Huawei Cloud
- [book club issue 13] packaging format of video files
- Application practice | 1billion data second level correlation. Huolala's OLAP System Evolution Based on Apache Doris (with PPT download)
- LeetCode226. 翻转二叉树
- Real time transformer: meituan's research on single image depth estimation
猜你喜欢

ADB regular use of work notes

Safety innovation practice | Haitai Fangyuan was invited to participate in the technical exchange Seminar on "network information innovation and value co creation in the digital age"

華為雲的AI深潜之旅

Live broadcast preview | can SQL also play industrial machine learning? Mlops meetup V3 takes you to the bottom!

华为云的AI深潜之旅

CORBA Architecture Guide (Common Object Request Broker Architecture)

Progress in visual weakly supervised learning
![[dynamic programming] p1018 linear DP: maximum product](/img/3f/b2f394f328c214937add7afa0568c3.jpg)
[dynamic programming] p1018 linear DP: maximum product

Postman introduction and installation steps

什么是接口?什么是接口测试?
随机推荐
开通股票炒股账号安全吗?是靠谱的吗?
How can the sports app keep the end-to-side background alive to make the sports record more complete?
CORBA Architecture Guide (Common Object Request Broker Architecture)
The further application of Li Kou tree
In one sentence, I will tell you the meaning of select 1, 2 and 3 in SQL injection, and explain the meaning of each part of SQL injection in detail
Golang JSON serializing and deserializing strings deserializing to map[string]interface{}
Construction and application of urban brain knowledge map
[width first search note] BFS output shortest path
LeetCode188. The best time to buy and sell stocks IV
Why use the rust language?
LeetCode117. 填充每个节点的下一个右侧节点指针_II
[Note: analog MOS integrated circuit] bandgap reference (basic principle + current mode + voltage mode circuit explanation)
CVPR 2022|极具创意&美感的文字生成方法!支持任意输入
Security dilemma of NFT liquidity agreement - Analysis of the hacked event of NFT loan agreement xcarnival
Leetcode daily question - 30 Concatenate substrings of all words
2022年股票在手机上开户安全吗?找谁可以办理?
LeetCode123. The best time to buy and sell stocks III
LeetCode116. Populate the next right node pointer for each node
LeetCode121. The best time to buy and sell stocks
Is it safe to open a stock trading account? Is it reliable?