Source:

PAT A1149 Dangerous Goods Packaging (25 分)

Description:

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 (≤), the number of pairs of incompatible goods, and M (≤), 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 (≤) 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

Keys:

  • 散列(Hash)

Attention:

  • 若1个元素与N个元素互斥,属于散列;若一系列元素相互排斥的话,则是并查集

Code:

 /*
Data: 2019-08-04 16:38:35
Problem: PAT_A1149#Dangerous Goods Packaging
AC: 32:04 题目大意:
题目大意:
给一份两两互斥的清单,再给出货品清单,判断该批货品是否兼容 基本思路:
二维数组存储各个物品的互斥集,
设置该批物品存在位=1,遍历该批物品的互斥集;
若互斥集中物品的存在位=1,则不兼容
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int M=1e6;
vector<int> st[M];
int exist[M],goods[M]; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,k,v1,v2;
scanf("%d%d", &n,&m);
for(int i=; i<n; i++)
{
scanf("%d%d", &v1,&v2);
st[v1].push_back(v2);
st[v2].push_back(v1);
}
while(m--)
{
scanf("%d", &k);
fill(exist,exist+M,);
for(int i=; i<k; i++)
{
scanf("%d", &goods[i]);
exist[goods[i]]=;
}
for(int i=; i<k; i++)
for(int j=; j<st[goods[i]].size(); j++)
if(exist[st[goods[i]][j]]==){
k=;break;
}
if(k) printf("Yes\n");
else printf("No\n");
} return ;
}

PAT_A1149#Dangerous Goods Packaging的更多相关文章

  1. pat 1149 Dangerous Goods Packaging(25 分)

    1149 Dangerous Goods Packaging(25 分) When shipping goods with containers, we have to be careful not ...

  2. PAT A1149 Dangerous Goods Packaging (25 分)——set查找

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  3. 1149 Dangerous Goods Packaging (25 分)

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  4. 1149 Dangerous Goods Packaging

    When shipping goods with containers, we have to be careful not to pack some incompatible goods into ...

  5. 2018.9.8pat秋季甲级考试

    第一次参加pat考试,结果很惨,只做了中间两道题,还有一个测试点错误,所以最终只得了不到50分.题目是甲级练习题的1148-1151. 考试时有些紧张,第一题第二题开始测试样例都运行不正确,但是调试程 ...

  6. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  7. PAT 2018 秋

    A 1148 Werewolf - Simple Version 思路比较直接:模拟就行.因为需要序列号最小的两个狼人,所以以狼人为因变量进行模拟. #include <cstdio> # ...

  8. SAP BAPI一览 史上最全

    全BADI一览  List of BAPI's       BAPI WG Component Function module name Description Description Obj. Ty ...

  9. BADI:LE_SHP_DELIVERY_PROC-增强在交货处理中

    1.所得方法清单: CHANGE_FCODE_ATTRIBUTES Control Activation of Function CodesCHANGE_FIELD_ATTRIBUTES Contro ...

随机推荐

  1. POJ 3278 Catch That Cow(求助大佬)

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 109702   Accepted: 34255 ...

  2. JS推断是否为JSON对象及是否存在某字段

    $.ajax({ type: 'POST', url: url, success(function(data){ //推断是否为JSON对象 if(typeof(data) == "obje ...

  3. Apache server配置

    Apacheserver在我们生活中非经常常使用 今天给大家将一下mac 下apache server的配置 这对程序来说是必备技能之中的一个,假设我们在公司开发都是用的公司的server 将自己的代 ...

  4. Cocos2d-x 开发神器cococreator使用介绍

    Cocos2d-x 开发神器cococreator使用介绍 本篇博客小巫给大家推荐一个开发神器,你还在为搭建Cocos2d-x开发环境而头痛么.还在为平台移植问题而困扰么,我想大家都想更加高速得进行开 ...

  5. poj 1741(树的点分治)

    Tree Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dis ...

  6. hdu 2205(容斥原理)

    Eddy's爱好 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. bzoj2503 相框——思路

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2503 思路题: 首先,这种问题应该注意到答案只跟度数有关,跟其他什么连接方法之类的完全无关: ...

  8. EOJ 1501/UVa The Blocks Problem

    Many areas of Computer Science use simple, abstract domains for both analytical and empirical studie ...

  9. .NET页面事件执行顺序

    摘自:http://www.cnblogs.com/kenkofox/archive/2011/03/18/1987998.html和http://blog.csdn.net/yiruoyun/art ...

  10. c++之——————各种变量

    对我们程序员来讲,“变量”和“对象”是可以相互互换使用的.-------------开篇之词. 变量:提供一个具有名字的可供程序操作的存储空间.由类型说明符和其后紧跟的数个列表组成,其中变量名之间使用 ...