PAT Advanced 1149 Dangerous Goods Packaging (25 )
题目描述
Input Specification:
Output Specification:
Sample Input:
Sample Output:
解题思路
解放不打卡的思想后,问题似乎变得简单了很多
Code
- AC代码
#include<bits/stdc++.h>
using namespace std;
struct Node{
int u, v;
};
int main() {
// freopen("in.txt", "r", stdin);
int N, M;
cin >> N >> M;
vector<Node> incompatible(N);
for(int i = 0; i<N; i++) {
cin >> incompatible[i].u >> incompatible[i].v;
}
int k, temp;
for(int i = 0; i<M; i++) {
cin >> k;
bool flag = true;
unordered_map<int, int> m;
for(int j = 0; j<k; j++) {
cin >> temp;
m[temp] = 1;
}
for(int j = 0; j<incompatible.size(); j++) {
int u = incompatible[j].u, v = incompatible[j].v;
if(m[u] && m[v]) {
flag = false;
break;
}
}
flag ? cout << "Yes\n" : cout << "No\n";
}
return 0;
}
总结
对于输入数据远大于查询数据的题,直接离线操作可以简单很多