1121 Damn Single
“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:
3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333
Sample Output:
5
10000 23333 44444 55555 88888
分析:先用map类型存储情侣双方的值。
输入M个数据,先判断是否在情侣中,如果不在,则是单身。
在情侣中,再判断情侣是否在party中,如果不在,则视为单身。
参考代码:

#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#define N 100008
int a[N];
using namespace std;
int main()
{memset(a, 0, sizeof(int)*(N));map<int, int>couple;set<int>s;int n,m, man, woman;scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d%d", &man, &woman);couple[man] = woman;couple[woman] = man;s.insert(man);s.insert(woman);}scanf("%d", &m);vector<int>res(m);for (int i = 0; i < m; i++) {scanf("%d", &res[i]);a[res[i]] = 1;}vector<int>v;sort(res.begin(), res.end());int flag = 0,  cnt = 0;for (auto val : res) {   //遍历flag = 0;if (s.count(val) == 0)flag = 1;else {int partner = couple[val];if (a[partner] == 0)flag = 1;}if (flag) {cnt++;v.push_back(val);}}printf("%d\n", cnt);flag = 0;if(cnt)for (auto val : v) {if (flag)printf(" "); printf("%05d", val);flag = 1;}return 0;
}

1121 Damn Single相关推荐

  1. PAT甲级1121 Damn Single :[C++题解]哈希表、结构体

    文章目录 题目分析 题目来源 题目分析 来源:acwing 思路:一对伴侣存入一个结构体中.查询的集合放入哈希表unordered_set<int> S;中.然后遍历每一对伴侣,如果同时存 ...

  2. 1121 Damn Single (25 分)

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  3. PAT 1121 Damn Single

    1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...

  4. PAT 甲级 1121  Damn Single

    1121 Damn Single (25 point(s)) "Damn Single (单身狗)" is the Chinese nickname for someone who ...

  5. 1121. Damn Single (25)

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

  6. 1121 Damn Single (25分)

    1121 Damn Single (25分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bein ...

  7. PAT 甲级1121 Damn Single

    1121 Damn Single "Damn Single (单身狗)" is the Chinese nickname for someone who is being sing ...

  8. PAT——1121 Damn Single 甲级

    1121 Damn Single 题目 题意 代码解析 AC代码 参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/99 ...

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

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

最新文章

  1. AngularJs--过滤器(filter)
  2. 如何在Java中检查字符串是否为数字
  3. python中的序列类型和序列号_python~序列类型及操作
  4. ubuntu双系统把win7设置为默认启动选项
  5. c语言中常用的预处理命令6,C语言的预处理命令
  6. 爬虫项目(三)---采集最近一日全国各省疫情数据
  7. python内建函数和工厂函数的整理
  8. linux 中常用安装配置
  9. Cocos2d-js-v3.2 在 mac 上配置环境以及编译到 Andorid 的注意事项(转)
  10. R+markdown+LaTeX 中文编译解决方案
  11. Ubuntu、SUSE的发音
  12. OSChina 周一乱弹 ——斯文眼镜男竟然对一只母喵做了这样的事情!
  13. 计算机网络原理_第8章 局域网技术 之二 令牌环
  14. X64切换到X32模式遇到的问题
  15. 基于欧几里德距离的推荐功能实现思路(向量空间)
  16. 每次开机都应用计算机配置,电脑win10每次重新开机设置都会还原怎么回事
  17. 让你的Mac桌面变得与众不同其实很简单
  18. liunx----putty--ssh--ppk---密文自动登陆
  19. 【开源项目】智能桌上足球
  20. 【机器学习】时间序列 ACF 和 PACF 理解、代码、可视化

热门文章

  1. 红旗linux 桌面10 下载,想要红旗桌面操作系统10(RedFlag Desktop Linux10)的请联系红旗官方...
  2. [英语阅读]投机者-Lame duck
  3. php设置header头实现将视频下载到客户端
  4. 化妆品APP开发快速制作
  5. 吻吻更健康!揭晓接吻的11大优点
  6. 日本市场智能电视的主要功能
  7. scite使用日常收集
  8. Metasploit的射频收发器功能 | Metasploit’s RF Transceiver Capabilities
  9. 计算机公式or,OR值的计算方法
  10. java培训 | 零基础学习java开发的学习方法有哪些