B - Roulette 解説 by en_translator
Several implementations are possible; for example, the sample code in the end of this editorial performs the following procedure.
First, receive the input.
Inspect people \(i = 1, 2, \ldots, N\). Store the people betting on \(X\) into the variable-length array \(\mathrm{vec}\).
For each person \(i\) in \(\mathrm{vec}\), count how many bets person \(i\) made and store the number to \(c_i\). Find the minimum value \(C_{\min}\) among them.
For each person \(i\) in \(\mathrm{vec}\), check if \(C_i = C_{\min}\), i.e. if that person made the minimum bets; if so, store it to the variable-length array \(\mathrm{ans}\).
Print the size of \(\mathrm{ans}\) and its elements in ascending order.
The following is a sample code in C++ language.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
int n, x, c[101];
vector<int> a[101];
cin >> n;
for(int i = 1; i <= n; i++){
cin >> c[i];
a[i].resize(c[i]);
for(int j = 0; j < c[i]; j++) cin >> a[i][j];
}
cin >> x;
vector<int> vec;
for(int i = 1; i <= n; i++){
for(int j = 0; j < c[i]; j++) if(a[i][j] == x) vec.push_back(i);
}
int cmin = 37;
for(auto i : vec) cmin = min(cmin, c[i]);
vector<int> ans;
for(auto i : vec) if(c[i] == cmin) ans.push_back(i);
cout << ans.size() << endl;
for(auto b : ans) cout << b << " ";
cout << endl;
return 0;
}
投稿日時:
最終更新: