题目链接: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. 编译驱动Makefile解析

    #ubuntu的内核源码树,如果要编译在ubuntu中安装的模块就打开这2个 #KERN_VER = $(shell uname -r) #KERN_DIR = /lib/modules/$(KERN ...

  2. python 字符串 string模块导入及用法

    字符串也是一个模块,有自己的方法,可以通过模块导入的方式来调用 1,string模块导入 import string 2,  其用法 string.ascii_lowercase string.dig ...

  3. 一些WinAPI 处理 字符的函数和连接(GetACP和SetThreadLocale最重要,还有SetConsoleCP)

    虽然东西都是现成的.但是也要脑子里有个概念. // 地区与语言GetACP 取得 ANSI code page,法语XP+设置中文内核 = 936 // ShowMessage(IntToStr(Ge ...

  4. Python 数据分析中金融数据的来源库和简单操作

    目录 金融数据 pandas-datareader TuShare 金融学图表 案例 金融数据 数据分析离不开数据的获取,这里介绍几种常用的获取金融方面数据的方法. pandas-datareader ...

  5. tomcat闪屏是jdk JAVA_HOEM环境变量配置问题

    JAVA_HOME=D:\jdk.18

  6. Python subprocess ffmpeg

    # -*- coding:utf-8 -*- import os, sys, getopt import numpy as np import subprocess as sp import cv2 ...

  7. C# 异常处理最佳实践,解决代码分析提示CA1031:不要捕捉一般异常类型的解决办法

    异常类型 异常一般分为系统异常 和 应用异常.系统异常有无法连接数据库,而应用异常是业务逻辑异常,比如授权失败. 在 C# 中异常基于 System.Exception,派生出 System.Syst ...

  8. Python3实现文本预处理

    1.数据集准备 测试数据集下载:https://github.com/Asia-Lee/Vulnerability_classify/blob/master/testdata.xls 停用词过滤表下载 ...

  9. Oracle11gR2 64bit+Oracle11gR2Client32bit+pl/sql 9

    安装Oracle数据库,费了老一番折腾准备软件:1. Oracle 11g R2 64bit2. Oracle 11g R2 Client 32bit3. PLSQL Developer V9 逐个安 ...

  10. [CQOI2015]网络吞吐量(网络流+SPFA)

    [CQOI2015]网络吞吐量 题目描述 路由是指通过计算机网络把信息从源地址传输到目的地址的活动,也是计算机网络设计中的重点和难点.网络中实现路由转发的硬件设备称为路由器.为了使数据包最快的到达目的 ...