PTA 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
题意
给定情侣关系,然后给出一次宴会上出席的人,问这些人中有多少单身狗 (伴侣没来的也算)。
思路
记录情侣关系,然后找出出席的人中不在情侣关系中的人以及伴侣没有来的人即可。
注意输出要补零,最后一行不用换行。
代码
#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的更多相关文章
- 1121 Damn Single (25 分)
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- PAT 1121 Damn Single[简单]
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PAT 1121 Damn Single
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- 1121. Damn Single (25)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 1121 Damn Single
题意: 给出n对情侣,然后给出聚会上的m个人,问这m个人中有几个人事落单的. 思路: 首先,开一个数组couple[]存储情侣间的映射关系:然后,用exist[]标记聚会上出现过的人:最后遍历0~N, ...
- PAT1121:Damn Single
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- PAT 甲级真题题解(63-120)
2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
随机推荐
- python 迭代器和生成器的区别
迭代器(iterator)是一个实现了迭代器协议的对象,python的一些内置数据类型(列表,数组,字符串,字典等)都可以通过for语句进行迭代,我们也可以自己创建一个容器,实现了迭代器协议,可以通过 ...
- SCUT - 153 - 小马哥和他的山脉 - 线段树
https://scut.online/p/153 其实不需要用线段树,只关心相邻元素的差,像神仙那样用差分就可以O1维护的. 但是我偏要用. 交之前写的那个,注意没有st本身的线段树只有lazy标记 ...
- C# EF优化
原文:https://www.cnblogs.com/wangyuliang/p/10338902.html https://www.cnblogs.com/simadi/p/6879366.ht ...
- C#控制文本框(TextBox)只能输入正数,负数,小数
由于项目需要,需要写一个TextBox文本框,此文本框需要满足:只能输入正数,负数和小数.比如:3,0.3,-4,-0.4等等. 在网上找了许多正则表达式都不好用,由于本人又对正则表达式 ...
- linux基础开发软件安装 - java相关
1.linux在线安装mysql:转自 https://www.cnblogs.com/bigbrotherer/p/7241845.html ,写的很好,简单易用. 开启远程访问:转 https:/ ...
- Linux时间命令date
date:打印当前时间 date "+定制信息":自定义格式打印时间 - date "+%H":打印当前时间的小时数 - date "+%H%M%S& ...
- zTree根节点默认打开
1.在生成tree的json数据中,直接给出:open:true的属性; 2.treeObj.expandAll(true); 3.var zTree = $.fn.zTree.getZTreeObj ...
- sqlserver 高版本迁移到低版本
奇葩事不少, 这不, 得把 sqlserver 2014 迁移到 2012 开始以为用备份再还原的方法就可以, 谁知道最终兼容性的问题无法解决(低版本不兼容高版本备份的文件, 即便在高版本中选择了兼 ...
- Mac sublime 安装包的时候出现 unable to download xxx (_ssl.c:548)
Mac sublime 安装包的时候出现 unable to download xxx前置条件:[本文行文中,所使用的电脑环境为 mac](当然不排除,在其他系统下,依然可以采用这种解决方案) 今天想 ...
- web编程jsp小tips
jsp文件头 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...