版权声明:个人整理,仅供参考,请勿转载,如有侵权,请联系[email protected] https://blog.csdn.net/mooe1011/article/details/88710389
荧幕上一共有 n 列,每次都会有一个 1 x 1 的方块随机落下,在同一列中,后落下的方块会叠在先前的方块之上,当一整行方块都被占满时,这一行会被消去,并得到1分。
有一天,小易又开了一局游戏,当玩到第 m 个方块落下时他觉得太无聊就关掉了,小易希望你告诉他这局游戏他获得的分数。
输入描述:
第一行两个数 n, m 第二行 m 个数,c1, c2, ... , cm , ci 表示第 i 个方块落在第几列 其中 1 <= n, m <= 1000, 1 <= ci <= n
输出描述:
小易这局游戏获得的分数
输入例子1:
3 9 1 1 2 2 2 3 1 2 3
输出例子1:
2
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m;
while(cin>>n>>m){
map<int,int> res;
int i = 0;
int x;
while(m--){
cin >> x;
res[x]++;
i++;
}
if (res.size() != n) {
cout << 0 << endl;
}
else {
vector<int> score;
for (auto p : res) {
score.push_back(p.second);
}
sort(score.begin(), score.end());
cout << score[0] << endl;
}
}
return 0;
}