PAT 1090 危险品装箱

这个和甲级的一道题重复了。

今天真的不适合写代码吧,一个下午就ac了3道题,头很大。

这道题有点像leetcode朋友圈,应该可以用并查集做,我用了map的方法,具体看代码吧。

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#include <queue>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cctype>
#include <set>
#include <deque>
#include <cmath>



using namespace std;





unordered_map<int, set<int>> hash_table;


int main(){
//        printf("123\n");
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0; i<n; i++) {
        int a,b;
        scanf("%d%d",&a,&b);
        hash_table[a].insert(b);
        hash_table[b].insert(a);
    }
    for (int i=0; i<m; i++) {
        int a;
        scanf("%d",&a);
        vector<int> pack;
        bool isIn[1000000] = { false };
        for (int j=0; j<a; j++) {
            int b;
            scanf("%d",&b);
            pack.push_back(b);
            isIn[b] = true;
        }
        
        bool flag = true;
        for (int j=0; j<a; j++) {
            for (auto it =hash_table[pack[j]].begin(); it!=hash_table[pack[j]].end(); it++) {
                if(isIn[*it]){
                    flag = false;
                    printf("No\n");
                    break;
                }
            }
            if(!flag)
                break;
        }
        if(flag)
            printf("Yes\n");
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值