PAT 甲级 1149  Dangerous Goods Packaging

【PAT (Advanced Level) Practice】1149 Dangerous Goods Packaging (25 分) 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 packe 阅读详情

1149 Dangerous Goods Packaging (25 point(s))

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

经验总结:

emmmm  大概就是 PAT 甲级 1121 Damn Single 的加强版,只不过一个人可以和多个人配对,这里说人比较不法治,所以就改成了危险物品(手动滑稽),思路是一样的,存储所有的对,然后对于给出的所有物品,将不能与其共存的物品的flag置为true,然后从头至尾访问所有物品的flag,如果flag为true,说明危险物共存,如果遍历结束仍未发现,则安全~

AC代码

#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int maxn=100010;
int n,m,a,b,k,goods[1010];
bool flag[maxn];
vector<int> couple[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)
	{
		scanf("%d%d",&a,&b);
		couple[a].push_back(b);
		couple[b].push_back(a);
	}
	for(int i=0;i<m;++i)
	{
		scanf("%d",&k);
		memset(flag,false,sizeof(flag));
		for(int j=0;j<k;++j)
		{
			scanf("%d",&goods[j]);
			for(int x=0;x<couple[goods[j]].size();++x)
				flag[couple[goods[j]][x]]=true;
		}
		int f=true;
		for(int j=0;j<k;++j)
		{
			if(flag[goods[j]]==true)
			{
				f=false;
				break;
			}
		}	
		printf("%s\n",f?"Yes":"No");
	}
	return 0;
}

 

Android 12.0 系统systemui状态栏下拉左滑显示通知栏右滑显示控制中心模块的流程分析 在android12.0的系统rom定制化开发中,在系统原生systemui进行自定义下拉状态栏布局的定制的时候,需要在systemui下拉状态栏下滑的时候,根据下滑坐标来 判断当前是滑出通知栏还是滑出控制中心模块,所以就需要根据屏幕宽度,来区分x坐标值为多少是左滑出通知栏或者右滑出控制中心模块,接下来分析下 状态栏下滑坐标等相关功能代码分析 阅读详情

相关推荐

FPGA之全数字锁相环(DPLL)

1. 数字锁相环的基本原理和组成 1.1 锁相环(PLL)的简介 锁相环最开始并不是用在数字电路中,而是模拟短路中。对于模拟电路中的锁相环,大家可以参考这篇文章稍微看一下,数字和模拟只是实现的方法不同,但是原理、步骤还是共同的。关于模拟PLL。可以参考一片文章: http://www.sohu.com/a/190569594_464086 首先在学习数字锁相环之前,我们应该先了解什么是锁相环?锁相...

DBLLLLLLLL的博客 5万+

【PAT甲级 - C++题解】1149 Dangerous Goods Packaging

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 623

ANSYS APDL 后处理:用*GET和ETABLE命令把节点/单元应力结果导出到TXT文件(附完整命令流)

本文详细介绍了在ANSYS APDL中使用*GET和ETABLE命令导出节点和单元应力数据到TXT文件的完整方案。通过节点解和单元解的核心逻辑分析,提供了从基础到进阶的数据导出方法,包括节点应力、单元应力数据的提取与格式化输出,以及高级技巧如选择性导出与数据过滤。帮助工程师高效完成有限元分析后处理工作。

weixin_26805597的博客 647

PAT 1149 Dangerous Goods Packaging

原题链接:1149 Dangerous Goods Packaging (25分) 关键词:hash、枚举 题目大意: 给定两两互斥的物品列表,判断给定的物品清单是否满足不存在互斥物品。

cwtnice的博客 266

数字IC设计避坑指南:为什么477条net的DRV问题无法修复?解析don‘t touch hierarchy的影响

本文深入解析了数字IC后端实现中,因“don't touch hierarchy”约束导致大量DRV违规(如477条net)无法自动修复的根本原因。文章以Cadence Innovus工具为例,详细阐述了DRV修复机制与设计保护约束的冲突原理,并提供了从日志定位、风险评估到分级解除约束的完整实战策略,帮助工程师有效解决此类设计收敛难题。

hope8的博客 293

Star CCM+ 202206 (17.04) 详细安装步骤

StarCCM+ 17.04 安装包和详细安装步骤

薛定谔的alpha狗 3万+

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 (氧...

小白的博客 445

STM32+CubeMX实战:5步搞定LWIP HTTP服务器搭建(附常见编译错误解决)

本文详细介绍了基于STM32和CubeMX平台,快速搭建LWIP HTTP服务器的5步实战指南。内容涵盖从项目初始化、LWIP深度配置到解决经典的`HTTPD_FSDATA_FILE`编译错误,并分享了使用VSCode进行高效开发的工作流,旨在帮助嵌入式开发者快速实现网络功能并规避常见陷阱。

weixin_29192365的博客 585

1149 Dangerous Goods Packaging (25分)简洁AC

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

C_P_J_M的博客 333

PYNQ开发板使用-使用DMA进行数据搬移(Simple DMA transfer 模式)

该篇是学习使用PYNQ开发板,实际上是对ZYNQ PL端AXI_CDMA 核的应用。实验步骤参照官网的教程,一步一步地做,但是由于在硬件资源布置方面与官方教程稍有出入,所以在SDK的源码里也进行了修改。 AXI_CDMA特性: 如果是使用ZYNQ 7系列芯片(可能其他Xilinx也是通用的),xilinx的AXI_CDMA 核有两种传输模式:轮询(poll)和中断(...

YGLeeeon的博客 3525

奥比中光Gemini335L SDK实战:从标定参数到3D点云转换

本文详细介绍了奥比中光Gemini 335L深度相机的SDK实战应用,重点讲解如何跳过繁琐的棋盘格标定,直接调用出厂预标定参数实现高效的3D点云转换。通过解析内参、外参获取及四种核心坐标转换模式,并结合OpenCV等工具,指导开发者快速将相机集成到机器人抓取、三维测量等项目中,实现开箱即用的3D视觉解决方案。

raspberrypi5的博客 651

PAT 甲级 1149 Dangerous Goods Packaging

PAT 甲级 1149 Dangerous Goods Packaging思路:代码: 思路: 1.将所有互斥物品存放于map中,然后依据货物清单逐一遍历每件物品的互斥物品是否在清单中; 2.货物清单可用大数组存放,以空间换时间,否则可能超时。 代码: #include<iostream> #include<unordered_map> #include<vector...

Yuhan的博客 233

储能电池管理系统介绍(一)

介绍储能BMS的架构以及各模块功能

manjixingkong1234的专栏 1922

PAT 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 (氧化剂)...

柳婼 の blog 3567

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

PAT——1149 Dangerous Goods Packaging 甲级

1149 Dangerous Goods Packaging题目题意题解AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/1038429908921778176 题意 先给出N行两两互不兼容的货物列表,再给出M行待检测的货物序列,如果货物序列中不存在互不兼容的货物输出Yes,否则输出No 题解 用unoreder_map存储货物的不兼容货物,接着在遍历待检测货物序列时,先用vis来记录哪些物品出现在序列中,如果发现不兼容

ljhsq的博客 173

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

1149 Dangerous Goods Packaging-PAT甲级

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 (氧化剂)...

amf12345的博客 272

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT甲级1149 Dangerous Goods Packaging (25分)|C++实现

一、题目描述 原题链接 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 (易

weixin_42393947的博客 405

PAT 甲级1149 Dangerous Goods Packaging

1149 Dangerous Goods Packaging 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...

cyberickk blog 175

pat甲级1149 1149 Dangerous Goods Packaging (25分)

pat甲级1149 1149 Dangerous Goods Packaging (25分) note:非并查集,水题,10分钟小代码 代码: #include <iostream> #include <vector> #include <unordered_map> using namespace std;

qq_44992782的博客 188

【PAT刷题甲级】1149.Dangerous Goods Packaging

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 packe

C_greenbird的博客 269

PAT甲级 1149 Dangerous Goods Packaging

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 158

PAT甲级题目1149 Dangerous Goods Packaging

题目大意: 看危险货物在一起不。 代码: #include <iostream> #include <vector> #include <map> using namespace std; int main() { int n, k, t1, t2; map<int,vector<int>> m; scanf("%d%d", &n, &k); for (int i = 0; i < n; i+

weixin_43801993的博客 172

【PAT甲级题解记录】1149 Dangerous Goods Packaging (25 分)

问题描述 有一批化学货品,会发生反应的货品不能放在一个集装箱,现在两两给定会互相发生反应的化学货品,再给出每一个集装箱的货品清单,分别求这些集装箱是否可安全装箱。 解题思路 首先明确一点,若AB会反应,BC会反应,那不代表AC会反应,所以这不是一个并查集的问题,而是一个映射的问题,用map可轻松解决。

retr0的博客 453

PAT甲级 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 (氧化剂)...

zhaohaibo的博客 505

【PAT甲级A1149】Dangerous Goods Packaging (25分)(c++)

1149 Dangerous Goods Packaging (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB 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 troub

小庄同学的博客 230
上一篇: PAT 甲级 1148  Werewolf - Simple Version
下一篇: PAT 甲级 1150  Travelling Salesman Problem
漫浸天空的雨色
博客等级 码龄15年 1303粉丝 523原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值