PAT_A1121#Damn Single
Source:
Description:
"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
Keys:
Code:
/*
Data: 2019-08-14 16:32:45
Problem: PAT_A1121#Damn Single
AC: 13:30 题目大意:
找出独自前往派对的人
输入:
第一行给出,伴侣数N<=5e4(意味着最多1e5个人)
接下来N行,p1,p2
接下来一行,出席人数M<=1e4
接下来一行,给出M个id(5位)
输出:
独自参加派对的人数
id递增 基本思路:
有一点需要注意下,id值可能为0,因此哈希表的初始值置-1就可以了;
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int M=1e5;
int cp[M],mp[M]={};
vector<int> pt,sg; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,v1,v2;
scanf("%d", &n);
fill(cp,cp+M,-);
for(int i=; i<n; i++)
{
scanf("%d%d", &v1,&v2);
cp[v1]=v2;
cp[v2]=v1;
}
scanf("%d", &n);
while(n--)
{
scanf("%d", &v1);
pt.push_back(v1);
mp[v1]=;
}
for(int i=; i<pt.size(); i++)
if(cp[pt[i]]==- || mp[cp[pt[i]]]==)
sg.push_back(pt[i]);
sort(sg.begin(),sg.end());
printf("%d\n", sg.size());
for(int i=; i<sg.size(); i++)
printf("%05d%c", sg[i],i==sg.size()-?'\n':' '); return ;
}
PAT_A1121#Damn Single的更多相关文章
- linux-关机出现Telling INIT to go to single user mode.无法关机
运行/sbin/shutdown now最后显示:Telling INIT to go to single user mode.INIT:Going single userINIT:Sending g ...
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [LeetCode] Single Number II 单独的数字之二
Given an array of integers, every element appears three times except for one. Find that single one. ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- First,FirstOrDefault,Single,SingleOrDefault的区别
操作符 如果源序列是空的 源序列只包含一个元素 源序列包含多个元素 First 抛异常 返回该元素 返回第一个元素 FirstOrDefault 返回default(TSource) 返回该元素 返回 ...
- 《Single Image Haze Removal Using Dark Channel Prior》一文中图像去雾算法的原理、实现、效果(速度可实时)
最新的效果见 :http://video.sina.com.cn/v/b/124538950-1254492273.html 可处理视频的示例:视频去雾效果 在图像去雾这个领域,几乎没有人不知道< ...
- LeetCode Single Number I / II / III
[1]LeetCode 136 Single Number 题意:奇数个数,其中除了一个数只出现一次外,其他数都是成对出现,比如1,2,2,3,3...,求出该单个数. 解法:容易想到异或的性质,两个 ...
- LeetCode——Single Number II(找出数组中只出现一次的数2)
问题: Given an array of integers, every element appears three times except for one. Find that single o ...
- [LeetCode] Single Number
Given an array of integers, every element appears twice except for one. Find that single one. Note: ...
随机推荐
- STM32例程之USB HID双向数据传输(源码下载)【转】
程序功能 将STM32的USB枚举为HID设备. STM32使用3个端点,端点0用于枚举用,端点1和2用于数据的发送和接收. 端点长度为64,也就是单次最多可以传输64个字节数据. STM32获取上位 ...
- Mac-VScode
1) 安装 xcode. 打开App Store,搜索xcode,进行下载安装. 2)执行命令: xcode-select --install 3)安装VS Code https://code.vis ...
- 前端之间的url 传值
转自:https://www.cnblogs.com/candy-Yao/p/8858166.html
- Example of dynamic programmatic description
- Suppose there are some itineraries in the Itinerary page, and you want to check on all of them. Se ...
- 深入JAVA虚拟机笔记-垃圾收集器与内存分配策略
第三章:垃圾收集器与内存分配 问题:1.哪些内存需要回收 2.什么时候回收 3.怎么回收 回收方法区:
- 软件开发程序猿日常必备,现用现查&日志记录
日志记录-- logging模块 日志用处: 1.记录用户信息 2.记录个人流水 3.记录软件的运行状态 4.记录程序员发出的指令(跳板机) 5.用于程序员代码调试(print特别消耗内存,在开发测试 ...
- 14-vim-替换命令-01-替换
命令 英文 功能 工作模式 r replace 替换当前字符 命令模式 R replace 进入替换模式 替换模式 R命令进入替换模式,输入新字符替换当前光标所在位置的字符,替换完成后,按下ESC可以 ...
- 微信小程序の微信js
一.Javascript简介 二.nodejs中的jscript nodejs表示谷歌基于v8引擎的一门后端语言, ECMA表示ECMA262标准的基本js,native表示nodejs本身的一些包, ...
- 【转载】vue-cli搭建的环境,用nginx做代理服务器,访问时显示:Invalid Host header
来源:https://blog.csdn.net/Cookysurongbin/article/details/86077241 vue-cli搭建的环境,用nginx做代理服务器,访问时显示:Inv ...
- 解决vue项目打包之后出现源代码的问题
config/index.js 页面找到productionSourceMap:ture 改为 productionSourceMap:false