abc 314 B
实现起来很复杂,参考了jiangly的写法,学到了很多,对于简单题,如果时间复杂度允许,用更多直接的模拟(如果手速足够)比想巧方法要快得多,也容易得多
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<std::vector<int>> A(N);
for (int i = 0; i < N; i++) {
int C;
std::cin >> C;
A[i].resize(C);
for (int j = 0; j < C; j++) {
std::cin >> A[i][j];
}
}
int X;
std::cin >> X;
std::vector<int> p;
for (int i = 0; i < N; i++) {
if (std::find(A[i].begin(), A[i].end(), X) != A[i].end()) {
p.push_back(i);
}
}
if (p.empty()) {
std::cout << 0 << "\n";
return 0;
}
int mn = 1E9;
for (auto i : p) {
mn = std::min(mn, int(A[i].size()));
}
std::vector<int> ans;
for (auto i : p) {
if (A[i].size() == mn) {
ans.push_back(i);
}
}
std::cout << ans.size() << "\n";
for (auto i : ans) {
std::cout << i + 1 << " \n"[i == ans.back()];
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<vector<int>> a(N);
for (int i = 0; i < N; i ++)
{
int c;
cin >> c;
a[i].resize(c);
for (int j = 0; j < c; j ++)
cin >> a[i][j];
}
int x;
cin >> x;
vector<int> p;
for (int i = 0; i < N; i ++)
{
if (find(a[i].begin(), a[i].end(), x) != a[i].end()) p.push_back(i);
}
if (p.empty())
{
cout << 0 << endl;
return 0;
}
int mn = 1E9;
for (auto i : p)
{
mn = min(mn, (int) a[i].size());
}
vector<int> ans;
for (auto i : p) if (mn == a[i].size()) ans.push_back(i);
cout << ans.size() << endl;
for (auto i : ans) cout << i + 1 << ' ';
cout << endl;
return 0;
}
abc 313 B
要点是两两关系,要排出高低,只有最强者没有高于他的