1149 Dangerous Goods Packaging (25 分)
When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂) must not be packed with flammable liquid (易燃液体), or it can cause explosion.
Now you are given a long list of incompatible goods, and several lists of goods to be shipped. You are supposed to tell if all the goods in a list can be packed into the same container.
Input Specification:
Each input file contains one test case. For each case, the first line gives two positive integers: N (≤104), the number of pairs of incompatible goods, and M (≤100), the number of lists of goods to be shipped.
Then two blocks follow. The first block contains N pairs of incompatible goods, each pair occupies a line; and the second one contains M lists of goods to be shipped, each list occupies a line in the following format:
K G[1] G[2] ... G[K]
where K (≤1,000) is the number of goods and G[i]'s are the IDs of the goods. To make it simple, each good is represented by a 5-digit ID number. All the numbers in a line are separated by spaces.
Output Specification:
For each shipping list, print in a line Yes if there are no incompatible goods in the list, or No if not.
Sample Input:
6 3
20001 20002
20003 20004
20005 20006
20003 20001
20005 20004
20004 20006
4 00001 20004 00002 20003
5 98823 20002 20003 20006 10010
3 12345 67890 23333
Sample Output:
No
Yes
Yes
#include<iostream>
#include<vector>
#include<map>
using namespace std; int main(){
map<string,vector<string> > m1;
map<string,int> m2;
vector<string> v;
int n,m;
cin >> n >> m;
string a,b;
while(n--){
cin >> a >> b;
m1[a].push_back(b);
m1[b].push_back(a);
}
int k;
while(m--){
cin >> k;
m2.clear();
v.clear();
bool flag = ;
while(k--){
cin >> a;
v.push_back(a);
m2[a] = ;
}
for(int i = ; i < v.size(); i++){
for(int j = ; j < m1[v[i]].size(); j++){
if(m2[m1[v[i]][j]] == ){
flag = ;
break;
}
}
}
if(flag) cout << "No" <<endl;
else cout << "Yes" <<endl;
}
return ;
}
1149 Dangerous Goods Packaging (25 分)的更多相关文章
- pat 1149 Dangerous Goods Packaging(25 分)
1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not ...
- 1149 Dangerous Goods Packaging
When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...
- PAT_A1149#Dangerous Goods Packaging
Source: PAT A1149 Dangerous Goods Packaging (25 分) Description: When shipping goods with containers, ...
- PAT A1149 Dangerous Goods Packaging (25 分)——set查找
When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...
- PTA - - 06-图1 列出连通集 (25分)
06-图1 列出连通集 (25分) 给定一个有NN个顶点和EE条边的无向图,请用DFS和BFS分别列出其所有的连通集.假设顶点从0到N-1N−1编号.进行搜索时,假设我们总是从编号最小的顶点出发, ...
- 中国大学MOOC-陈越、何钦铭-数据结构-2015秋 01-复杂度2 Maximum Subsequence Sum (25分)
01-复杂度2 Maximum Subsequence Sum (25分) Given a sequence of K integers { N1,N2, ..., NK }. ...
- PTA 字符串关键字的散列映射(25 分)
7-17 字符串关键字的散列映射(25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义的散列函数H(Key)将关键字Key中的最后3个字符映射为整数,每个字符占5位:再用除留余 ...
- PTA 旅游规划(25 分)
7-10 旅游规划(25 分) 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条 ...
- L2-006 树的遍历 (25 分) (根据后序遍历与中序遍历建二叉树)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805069361299456 L2-006 树的遍历 (25 分 ...
随机推荐
- 单机配置tomcat 8 集群
如何能在集群中的多个节点之间保持数据的一致性,会话(Session)信息是这些数据中最重要的一块. 本文当采用tomcat默认集群配置(<Cluster className="org. ...
- Solidity部署问题
Solidity是一个有诸多限制的语言,部署智能合约以及运行都需要gas. 部署的时候如果程序太大,所需要的gas会超过一个区块的上限,这样就没法部署合约.如果用metamask测试的话会弹出以下警告 ...
- C# 世界坐标 页面坐标 PageUnit PageScale
PageScale: 获取或设置此 Graphics 的世界单位和页单位之间的比例.PageUnit: 获取或设置用于此 Graphics 中的页坐标的度量单位. 话不多说,上代码: privat ...
- java IO Nio 文件拷贝工具类Files
public static void main(String[] args) throws Exception { Files.copy(Paths.get("file/text.txt&q ...
- (转)使用Jquery+EasyUI进行框架项目开发案例讲解之一---员工管理源码分享
原文地址:http://www.cnblogs.com/huyong/archive/2013/09/24/3334848.html 使用Jquery+EasyUI 进行框架项目开发案例讲解之一 员工 ...
- 三维GIS
三维GIS数据结构 三维GIS数据库 三维渲染显示 点云处理 cnki:http://kns.cnki.net/kns/brief/default_result.aspx
- How do I create a .pyc file?
Python automatically compiles your script to compiled code, so called byte code, before running it. ...
- query聚类技术
query聚类 目的 query聚类主要有以下两个目的 解决query空间稀疏问题(长尾query) 挖掘用户意图(一条行为包含的意图是稀疏的,当有一簇行为时,意图更明确) 可以说聚类是构建内容模型的 ...
- C# 判断一个数是不是奇数/偶数
一般普通版: private bool IsOdd(int num) { ) == ; } 通过判断取余 现在升级版: private bool IsOdd(int num) { ) == ; } 通 ...
- GitHub团队协作流程
说来惭愧,这么长时间,第一次参与修改开源项目,所以整理了一份GitHub团队协作流程,作为备忘,文章大部分内容参考https://www.cnblogs.com/schaepher/p/4933873 ...