"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 50,000), the total number of couples. Then N lines of the couples follow, each gives a couple of ID's which are 5-digit numbers (i.e. from 00000 to 99999). After the list of couples, there is a positive integer M (≤10,000) followed by M ID's of the party guests. The numbers are separated by spaces. It is guaranteed that nobody is having bigamous marriage (重婚) or dangling with more than one companion.

Output Specification:

First print in a line the total number of lonely guests. Then in the next line, print their ID's in increasing order. The numbers must be separated by exactly 1 space, and there must be no extra space at the end of the line.

Sample Input:

  1. 3
  2. 11111 22222
  3. 33333 44444
  4. 55555 66666
  5. 7
  6. 55555 44444 10000 88888 22222 11111 23333

Sample Output:

  1. 5
  2. 10000 23333 44444 55555 88888
  3.  
  4. 使用couple记录是否有配偶
    使用flag标记是否配偶到场
    注意:最后不要输出换行,不然一旦没有输出,那么就有两个换行了!
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4. int main()
  5. {
  6. int n, m, boy, girl, id;
  7. int couple[], flag[];
  8. set<int>guests, res;
  9. cin >> n;
  10. fill(couple, couple + , -);
  11. fill(flag, flag + , );
  12. while (n--)
  13. {
  14. cin >> boy >> girl;
  15. couple[boy] = girl;
  16. couple[girl] = boy;
  17. }
  18. cin >> m;
  19. while (m--)
  20. {
  21. cin >> id;
  22. guests.insert(id);
  23. if (couple[id] == -)
  24. continue;
  25. else if (flag[id] == )//对偶没有来
  26. {
  27. flag[id] = ;
  28. flag[couple[id]] = ;
  29. }
  30. else if (flag[id] == )//对偶来了
  31. {
  32. flag[id] = -;
  33. flag[couple[id]] = -;
  34. }
  35. }
  36. for (auto a : guests)
  37. {
  38. if (flag[a] != -)
  39. res.insert(a);
  40. }
  41. cout << res.size() << endl;
  42. for (auto a : res)
  43. printf("%s%05d", (a == *(res.begin()) ? "" : " "), a);
  44. return ;
  45. }

PAT甲级——A1121 Damn Single【25】的更多相关文章

  1. PAT甲级 1121. Damn Single (25)

    1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...

  2. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  3. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  4. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  5. PAT甲级 1122. Hamiltonian Cycle (25)

    1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  6. PAT甲级 1126. Eulerian Path (25)

    1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...

  7. PAT甲级 1130. Infix Expression (25)

    1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...

  8. PAT甲级 1129. Recommendation System (25)

    1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

随机推荐

  1. quartz的使用(二.基本过程)

    1.关于各个要素的创建,SchedulerFactoryBean,CronTriggerFactoryBean及JobDetailFactoryBean全部实现spring中的FactoryBean& ...

  2. 如何在Windows10操作系统下安装superset步骤分享

    superset是一个轻量级自助式BI框架,以优雅的界面和根据数据表动态生成数据为主要特点. 一. 环境 windows 10 64位 Python 3.7 二. 安装步骤 安装Python 建议安装 ...

  3. 前置控制器一DispatcherServlet

    org.springframework.web.servlet.DispatcherServlet 前言 DispatcherServlet是SpringMVC的核心控制器,就像是SpringMVC的 ...

  4. 通过jquery获取页面信息

    获取浏览器显示区域(可视区域)的高度 : $(window).height(); 获取浏览器显示区域(可视区域)的宽度 :$(window).width(); 获取页面的文档高度 $(document ...

  5. php基本,输出 ,变量

    <?php   //php开头//单行注释/*多行注释*/ echo "hello word";//输出 方式连续输出多个字符串print"hello word&q ...

  6. bzoj1001题解

    [解题思路] 显然,这题的答案是这个网格图的最小割.根据最大流-最小割定理,我们可以用网络流算法来求其最小割,时间复杂度最小为O(V2√E). 特殊的,这个网格图是一个平面图,于是可以根据平面图最小割 ...

  7. centos7.4安装kubernetes1.6.0(开启TLS认证)

    目录 目录 前言 集群详情 环境说明 安装前准备 提醒 一.创建TLS证书和秘钥 安装CFSSL 创建 CA (Certificate Authority) 创建 CA 配置文件 创建 CA 证书签名 ...

  8. 剑指offer——10跳台阶演变

    题目描述 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法.   题解: 纯找规律题:   class Solution { public: ...

  9. Windows环境下安装openface

    由于昨天在学习人脸识别,就涉及到了openface 我使用的是Windows环境下的pycharm开发工具,昨天一直安装openface但就是没有相关的教程,使用pip install openfac ...

  10. boost库之pool编译错误

    1,编译错误截图 2,解决方法 这是由于没有链接对应的库导致的错误,在编译命令中加上 -lboost_system选项即可.