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?(10?4??), 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 = 0;while(k--){cin >> a;v.push_back(a);m2[a] = 1;}for(int i = 0; i < v.size(); i++){for(int j = 0; j < m1[v[i]].size(); j++){if(m2[m1[v[i]][j]] == 1){flag = 1;break;}}}if(flag) cout << "No" <<endl;else cout << "Yes" <<endl;}return 0;
}

?

轉載于:https://www.cnblogs.com/wanghao-boke/p/10458780.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/385114.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/385114.shtml
英文地址,請注明出處:http://en.pswp.cn/news/385114.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《數據結構與算法》

序號內容1排序算法概念2快速排序算法3堆排序算法4歸并排序算法

一個類的指針指向NULL去訪問該類的成員函數

對象指針為NULL&#xff0c;為什么還是可以調用成員函數

1091 N-自守數 (15 分)

如果某個數 K 的平方乘以 N 以后&#xff0c;結果的末尾幾位數等于 K&#xff0c;那么就稱這個數為“N-自守數”。例如 392?2??25392&#xff0c;而 25392 的末尾兩位正好是 92&#xff0c;所以 92 是一個 3-自守數。 本題就請你編寫程序判斷一個給定的數字是否關于某個 N 是…

1092 最好吃的月餅 (20 分

月餅是久負盛名的中國傳統糕點之一&#xff0c;自唐朝以來&#xff0c;已經發展出幾百品種。 若想評比出一種“最好吃”的月餅&#xff0c;那勢必在吃貨界引發一場腥風血雨…… 在這里我們用數字說話&#xff0c;給出全國各地各種月餅的銷量&#xff0c;要求你從中找出銷量冠軍…

86. 分隔鏈表

給定一個鏈表和一個特定值 x&#xff0c;對鏈表進行分隔&#xff0c;使得所有小于 x 的節點都在大于或等于 x 的節點之前。 你應當保留兩個分區中每個節點的初始相對位置。 示例: 輸入: head 1->4->3->2->5->2, x 3 輸出: 1->2->2->4->3->5 來…

1094 谷歌的招聘 (20 分)

2004 年 7 月&#xff0c;谷歌在硅谷的 101 號公路邊豎立了一塊巨大的廣告牌&#xff08;如下圖&#xff09;用于招聘。內容超級簡單&#xff0c;就是一個以 .com 結尾的網址&#xff0c;而前面的網址是一個 10 位素數&#xff0c;這個素數是自然常數 e 中最早出現的 10 位連續…

Observer觀察者模式

#include <iostream> #include <list> using namespace std;class Observer;class Subject { //抽象被觀察者 public:virtual void Attach(Observer*) 0;virtual void Detach(Observer*) 0;virtual void Notify() 0;virtual int GetState() { return state_; }v…

1093 字符串A+B (20 分)

給定兩個字符串 A 和 B&#xff0c;本題要求你輸出 AB&#xff0c;即兩個字符串的并集。要求先輸出 A&#xff0c;再輸出 B&#xff0c;但重復的字符必須被剔除。 輸入格式&#xff1a; 輸入在兩行中分別給出 A 和 B&#xff0c;均為長度不超過 10?6??的、由可見 ASCII 字符…

1095 解碼PAT準考證 (25 分)

PAT 準考證號由 4 部分組成&#xff1a; 第 1 位是級別&#xff0c;即 T 代表頂級&#xff1b;A 代表甲級&#xff1b;B 代表乙級&#xff1b;第 2~4 位是考場編號&#xff0c;范圍從 101 到 999&#xff1b;第 5~10 位是考試日期&#xff0c;格式為年、月、日順次各占 2 位&am…

《基礎算法》

序號內容1工廠模式2觀察者模式3單例模式4策略模式5memcpy、memmove6strpcy7strcat8strcmp9快速排序算法10歸并排序算法11堆排序算法

C++ STL之Vector

向量 vector 是一種對象實體, 能夠容納許多其他類型相同的元素, 因此又被稱為容器。 vector 屬于STL(Standard Template Library, 標準模板庫)中的一種自定義的數據類型, 可以廣義上認為是數組的增強版。vector是C用于數組類的容器&#xff0c;它可以被近似的認為是一個自動增長…

字符流中第一個不重復的字符

題目描述 請實現一個函數用來找出字符流中第一個只出現一次的字符。例如&#xff0c;當從字符流中只讀出前兩個字符"go"時&#xff0c;第一個只出現一次的字符是"g"。當從該字符流中讀出前六個字符“google"時&#xff0c;第一個只出現一次的字符是&q…

C++ STL之Set

set是關聯容器&#xff0c;類似于集合。 特點是里面的元素不會重復&#xff0c;而且元素時有序的。 1.聲明定義&#xff1a; #include<set>using namespace std;set<int> s; 2.常見用法 s.inert(5); //插入 s.begin(); //返回s的第一個元素 s.end(); // 返回最后一…

表示數值的字符串

題目描述 請實現一個函數用來判斷字符串是否表示數值&#xff08;包括整數和小數&#xff09;。例如&#xff0c;字符串"100","5e2","-123","3.1416"和"-1E-16"都表示數值。 但是"12e","1a3.14","…

數據庫簡單實用(一)

一、實驗環境&#xff1a; MySQL 2.7.22 xfce終端 二、開發準備 打開MySQL服務并使用root登錄 sudo service mysql start //打開mysql服務 mysql -u root //使用root用戶登錄&#xff0c;密碼為空 -u和root之間可以不用空格 三、實驗步驟 //如果在操作中忘掉&#xff1b;可以使…

lambda 表達式定制操作

泛型算法中的定制操作 許多算法都會比較輸入序列中的元素以達到排序的效果&#xff0c;通過定制比較操作&#xff0c;可以控制算法按照編程者的意圖工作。 普通排序算法&#xff1a;template<class RandomIterator> void sort(RandomIterator first,RandomIterator last)…

包含min函數的棧

題目描述 定義棧的數據結構&#xff0c;請在該類型中實現一個能夠得到棧中所含最小元素的min函數&#xff08;時間復雜度應為O&#xff08;1&#xff09;&#xff09;。 解法&#xff1a; class Solution { public:stack<int> s;stack<int> s_min;void push(int v…

01-復雜度3 二分查找 (20 分)

本題要求實現二分查找算法。 函數接口定義&#xff1a; Position BinarySearch( List L, ElementType X );其中List結構定義如下&#xff1a; typedef int Position; typedef struct LNode *List; struct LNode {ElementType Data[MAXSIZE];Position Last; /* 保存線性表中最后…

二叉樹的鏡像

題目描述 操作給定的二叉樹&#xff0c;將其變換為源二叉樹的鏡像。 輸入描述: 二叉樹的鏡像定義&#xff1a;源二叉樹 8/ \6 10/ \ / \5 7 9 11鏡像二叉樹8/ \10 6/ \ / \11 9 7 5 解法&#xff1a; /* struct TreeNode {int val;struct TreeNode *left;struct Tre…

01-復雜度1 最大子列和問題 (20 分)

給定K個整數組成的序列{ N?1??, N?2??, ..., N?K?? }&#xff0c;“連續子列”被定義為{ N?i??, N?i1??, ..., N?j?? }&#xff0c;其中 1≤i≤j≤K。“最大子列和”則被定義為所有連續子列元素的和中最大者。例如給定序列{ -2, 11, -4, 13, -5, -2 }&#x…