题目链接:1121 Damn Single (25 分)

"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

题意

给定情侣关系,然后给出一次宴会上出席的人,问这些人中有多少单身狗 (伴侣没来的也算)。

思路

记录情侣关系,然后找出出席的人中不在情侣关系中的人以及伴侣没有来的人即可。

注意输出要补零,最后一行不用换行。

代码

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10; int couple[maxn] = {-1}; int main() {
int n, m;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
int x, y;
scanf("%d%d", &x, &y);
couple[x] = y;
couple[y] = x;
}
scanf("%d", &m);
vector<int> party;
for(int i = 0; i < m; ++i) {
int x;
scanf("%d", &x);
party.push_back(x);
}
set<int> ans;
for(int i = 0; i < m; ++i) {
int tmp = couple[party[i]];
if(tmp == -1) {
ans.insert(party[i]);
} else {
if(find(party.begin(), party.end(), tmp) == party.end()) {
ans.insert(party[i]);
}
}
}
cout << ans.size() << endl;
for (auto it = ans.begin(); it != ans.end(); ++it) {
if(it != ans.begin()) {
printf(" ");
}
printf("%05d", *it);
}
printf("\n");
return 0;
}

PTA 1121 Damn Single的更多相关文章

  1. 1121 Damn Single (25 分)

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

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

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

  3. PAT 1121 Damn Single[简单]

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

  4. PAT 1121 Damn Single

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  5. 1121. Damn Single (25)

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  6. PAT甲题题解-1121. Damn Single (25)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. 1121 Damn Single

    题意: 给出n对情侣,然后给出聚会上的m个人,问这m个人中有几个人事落单的. 思路: 首先,开一个数组couple[]存储情侣间的映射关系:然后,用exist[]标记聚会上出现过的人:最后遍历0~N, ...

  8. PAT1121:Damn Single

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

  9. PAT 甲级真题题解(63-120)

    2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...

随机推荐

  1. [2019杭电多校第三场][hdu6609]Find the answer(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6609 大致题意是求出每个位置i最小需要将几个位置j变为0(j<i),使得$\sum_{j=1}^ ...

  2. dfs(枚举)

    http://codeforces.com/gym/100989/problem/L L. Plus or Minus (A) time limit per test 1.0 s memory lim ...

  3. 浅谈格雷码(Grey Code)在信息学竞赛中的应用

    1.格雷码的概念 1.性质 格雷码(Grey Code),又叫循环二进制码或反射二进制码,是一种编码方式,它的基本特点是任意两个相邻的格雷码只有一位二进制数不同. 常用的二进制数与格雷码间的转换关系如 ...

  4. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  5. 二分查找---有序数组的 Single Element

    有序数组的 Single Element 540. Single Element in a Sorted Array (Medium) Input: [1, 1, 2, 3, 3, 4, 4, 8, ...

  6. nginx入门(一)

    什么是nginx? nginx是一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.由俄罗斯的程序设计师Igor Sysoev所开发,官方测试nginx能够支支撑5 ...

  7. css设置不允许复制文本内容

    之前做一个网上答题的页面时,考虑到要防止考生利用复制粘贴来提高作弊的可能性,就设计了不允许复制.方法也很简单,通过设置CSS 的 user-select就可以达到目的: -moz-user-selec ...

  8. [Windows] GIF编辑器

    目录 1. 功能简介 2. 下载地址 3. 使用教程 3.1. 其他视频转gif的方案 1. 功能简介 可以自定义录屏位置.区域大小做GIF 可以编辑GIF.压缩GIF等 可以将视频转换成GIF 可以 ...

  9. 关于conda-新手必读

    一.管理conda 通过anaconda来安装python及python包,让你不必关心系统是否安装了一些依赖,如zlib等等,anaconda已经集成了这些依赖,可以方便的安装python 下载请点 ...

  10. java 小数精确计算

    小数精确计算 System.out.println(2.00 -1.10);//0.8999999999999999 上面的计算出的结果不是 0.9,而是一连串的小数.问题在于1.1这个数字不能被精确 ...