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: ...
随机推荐
- LeetCode题:旋转链表
原题: 给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: 1->2->3->4->5->NULL, k = 2输出: ...
- kruskal算法【最小生成树2】
设G=(V,E)是无向连通带权图,V={1,2,…,n}: 设最小生成树T=(V,TE),该树的初始状态为只有n个顶点而无边的非连通图T=(V,{}),Kruskal算法将这n个顶点看成是n个孤立的连 ...
- 5.如何使用jmeter参数话
参数化:简单的来理解一下,我们录制了一个脚本,这个脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密码同时登录,或者更好的模拟多个用户来登录系统.这个时候就需要对用户名和密码进行参 ...
- Java继承和构造函数
构造函数不是类的成员,它们不是由子类继承的.它们用于初始化实例变量. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class CSuper { public ...
- UVA11134_Fabled Rooks
大概题意: 在n*n的棋盘上面放n个车,能否使他们互相不攻击(即不能在同一行一列),并且第i个车必须落在第i的矩形范围(xl,yl, xr,yr)之内 xy互相并不干扰,所以就可以把这个二维问题压缩成 ...
- shell编程:字符串处理方式
字符串处理方式 计算字符串长度 获取子串在字符串中的索引位置 计算子串长度 抽取(截取)字串 1.计算字符串长度,有两种方式 $ ${#string} $ expr length "$str ...
- C语言中各种进制的表示
#include<stdio.h> int main() { //默认情况下是十进制 ; // 二进制(0b或者0B开头) int number2 = 0b1100; //八进制(0开头) ...
- Puppeteer自动化批量上传抖音视频
前言:最近因为项目宣传,所以用Puppeteer写了一个批量上传抖音视频的自动化程序用于推广. 环境和依赖:node,puppeteer 废话不多说,直接上代码: const puppeteer =r ...
- .net EntityFramework dbContext 如何实例化
1 .DbContext怎么在Asp.mvc中使如何实例化 public class Repository { //实例化EF容器:有弊端.一个线程里可能会创建多个DbContext //DbCont ...
- Activiti学习笔记3 — 流程定义
一.创建流程引擎对象 private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); 二.发布一个流程 ...