题目链接: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. Monitor HDU6514 二维差分入门学习

    Monitor HDU 6514 二维差分入门学习 题意 小腾有\(n*m\)的田地,但是有小偷来偷东西,在一片矩形区域上,有一部分区域是监控可以覆盖到的,这部分区域由一个或多个包含于该矩形区域的小矩 ...

  2. Codeforces - 1198C - Matching vs Independent Set - 贪心

    https://codeforces.com/contest/1198/problem/C 要选取一个大小大于等于n的匹配或者选取一个大小大于等于n的独立集. 考虑不断加入匹配集,最终加入了x条边. ...

  3. C#判断页面中的多个文本框输入值是否有重复的实现方法

    List<string> list = new List<string>();//首先定义一个泛型数组 //这里假如说有四个文本框 string mainseat = this ...

  4. Android客户端与Python服务器端通信之上传图片

    继上篇成功的与服务器端通信上之后,我现在需要将安卓本地的图片上传到服务端.服务端接收图片存下来. 参考:https://blog.csdn.net/qq_26906345/article/detail ...

  5. 信号量Semaphore实现原理

    Semaphore用于管理信号量,在并发编程中,可以控制返访问同步代码的线程数量.Semaphore在实例化时传入一个int值,也就是指明信号数量.主要方法有两个:acquire()和release( ...

  6. Tomcat 保存镜像实战操作( 目录挂载方法 )

    查看数据保存的位置 docker inspect --format='{{.Mounts}}' mxg_tomcat 宿主机数据保存在 /usr/local/project , 将此路径数据备份在 b ...

  7. tf.trainable_variables和tf.all_variables的对比

    tf.trainable_variables返回的是可以用来训练的变量列表 tf.all_variables返回的是所有变量的列表

  8. Oracle Set操作

    并集合 union/uinon all union 会去重,uinon all 不去重 交集 intersect 差集 minus

  9. c# tcp 服务客户端

    session connection protobuf-net

  10. 使用国外 DNS 造成国内网站访问慢的解决方法

    本文原载于 wzyboy's blog,转载请注明本文地址: https://wzyboy.im/post/874.html ,谢谢合作. 为什么要用国外 DNS 由于众所周知的问题,国内 DNS 服 ...