AtCoder Shop has N products. The price of the i-th product (1≤i≤N) is P i . The i-th product (1≤i≤N) has C i functions. The j-th function (1≤j≤C i ) of the i-th product (1≤i≤N) is represented as an integer F i,j between 1 and M, inclusive. Takahashi wonders whether there is a product that is strictly superior to another. If there are i and j (1≤i,j≤N) such that the i-th and j-th products satisfy all of the following conditions, print Yes; otherwise, print No. P i ≥P j . The j-th product has all functions of the i-th product. P i >P j , or the j-th product has one or more functions that the i-th product lacks. Constraints 2≤N≤100 1≤M≤100 1≤P i ≤10 5 (1≤i≤N) 1≤C i ≤M (1≤i≤N) 1≤F i,1 <F i,2 <⋯<F i,C i ≤M (1≤i≤N) All input values are integers. 代码解答C++语言
时间: 2024-04-17 10:22:58 浏览: 118
Sure! Here's a possible C++ implementation for the problem:
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> P(N);
vector<vector<int>> F(N, vector<int>(M+1, 0));
for (int i = 0; i < N; i++) {
cin >> P[i];
int C;
cin >> C;
for (int j = 0; j < C; j++) {
int func;
cin >> func;
F[i][func] = 1;
}
}
string answer = "No";
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
bool isSuperior = true;
if (P[i] >= P[j]) {
for (int k = 1; k <= M; k++) {
if (F[i][k] > F[j][k]) {
isSuperior = false;
break;
}
}
if (isSuperior) {
answer = "Yes";
break;
}
}
}
if (answer == "Yes") {
break;
}
}
cout << answer << endl;
return 0;
}
```
This code reads the input values, stores the product prices and functions in vectors, and then checks if there exists a product that is strictly superior to another according to the given conditions. It does this by iterating through each pair of products and comparing their prices and functions. The answer is stored in the `answer` string variable and printed at the end.
Note: This is just one possible implementation. There may be other ways to solve the problem.
阅读全文