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: ...
随机推荐
- PAT_A1097#Deduplication on a Linked List
Source: PAT A1097 Deduplication on a Linked List (25 分) Description: Given a singly linked list L wi ...
- 使用postman做接口测试----柠檬不萌!
目录 一.GET和POST请求的区别 二.http协议 1.http请求分为两个部分 2.http状态码 三.使用postman测试HTTP接口 1.请求方式:get 2.请求方式:post 3.请求 ...
- Centos7安装 Hadoop(单节点)
1.Hadoop简介 Hadoop是一个由Apache基金会所开发的开源分布式系统基础框架,使用Java开发,是处理大规模数据的软件平台. Hadoop可以从单一节点扩展到上千节点.用户可以在不了解分 ...
- 常用内置模块(一)——time、os、sys、random、shutil、pickle、json
常用内置模块 一.time模块 在python中,时间分为3种 1.时间戳: timestamp,从1970年1月1日到现在的秒数, 主要用于计算两个时间的差 2.localtime ...
- MySQL数据库学习初步
我使用的环境是Win7,开始学习PHP和MySQL,并且买了本<Head First PHP & MySQL>,可以从Head First Labs官网获得HeadFirst系列书 ...
- 转 关于HTTP和HTTPS的区别
关于HTTP和HTTPS的区别 运维猿 2018-12-01 07:30:00 一 HTTP和HTTPS的基本概念 1.HTTP:是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答 ...
- centos7.3 安装gitlab
系统自带ruby版本太低,需要手动编译2.4版本
- Anjular的ng-repeat
Anjular的ng-repeat不会循环一个二维集合中的一维集合.举个例子:集合 list= {1,2,{0,1,2},23,222},small={0,1,2},使用ng-repeat" ...
- 第一记 搭建Java集成开发环境
一.JDK JDK可以前往oracle官网进行下载并进行安装(我这边使用的是jdk1.8版本,也推荐使用jdk1.8及以上的) 下图是默认路径安装完成后的截图 安装完成会产生这两个文件夹 二.配置环境 ...
- 菩提圣心诀---zabbix自定义key监控oracle连接状态(python脚本)
目的:此次实验目的是为了zabbix服务端能够实时监控某服务器上oracle实例能否正常连接 环境:1.zabbix_server 2.zabbix_agent(含有oracle) 主要知识点: 1. ...