PAT甲级 1121. Damn Single (25)
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 (<=50000), 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 (<=10000) 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
——————————————————————————————————
题目的意思是先给出n组数,每组的两个数表示一对在查询每个人,如果一个人没对象或者他对象不再查询里就把他输出,输出按编号从小到大输出
思路:开数组记录每个人的对象,把查询的人先标记一下,再把对象没标记或没对象的人扔进set里输出
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <climits>
using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
int link[1000006];
bool flag[1000006];
int a[1000006];
int main()
{
int n,x,y,m;
scanf("%d",&n);
memset(link,-1,sizeof link);
for(int i=-0; i<n; i++)
{
scanf("%d%d",&x,&y);
link[x]=y;
link[y]=x;
}
scanf("%d",&m);
memset(flag,0,sizeof flag);
for(int i=0; i<m; i++)
{
scanf("%d",&a[i]);
flag[a[i]]=1;
}
set<int>s;
for(int i=0; i<m; i++)
{
if(flag[link[a[i]]]==0||link[a[i]]==-1)
s.insert(a[i]);
} printf("%d\n",s.size());
if(s.size()==0)
return 0;
set<int>::iterator it=s.begin();
int q=0;
for(; it!=s.end(); it++)
{
if(q++)
printf(" ");
printf("%05d",*it);
}
printf("\n");
return 0;
}
PAT甲级 1121. Damn Single (25)的更多相关文章
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT甲级——A1121 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特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT甲级 1122. Hamiltonian Cycle (25)
1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT甲级 1126. Eulerian Path (25)
1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...
- PAT甲级 1130. Infix Expression (25)
1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...
- PAT甲级 1129. Recommendation System (25)
1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
随机推荐
- document.write : 什么是在html输出中使用,什么是文档加载后使用?
理解:您只能在 HTML 输出中使用 document.write.如果您在文档加载后使用该方法,会覆盖整个文档. Javascript中只能在 HTML 输出流中使用 document.write, ...
- PAT 1085 PAT单位排行(25)(映射、集合训练)
1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随 ...
- linux利用crontab设置定时任务运行jar包
参考链接: 1.http://blog.csdn.net/javadhh/article/details/42779505 2.http://blog.csdn.net/cctv_liu/articl ...
- MySQL学习笔记-锁相关话题
在事务相关话题中,已经提到事务隔离性依靠锁机制实现的.在本篇中围绕着InnoDB与MyISAM锁机制的不同展开,进而描述锁的实现方式,多种锁的概念,以及死锁产生的原因. Mysql常用存储引擎的锁 ...
- [SoapUI] 通过JSONAssert比较两个环境的JSON Response,定制化错误信息到Excel
package ScriptLibrary; import org.json.JSONArray; import org.json.JSONException; import org.json.JSO ...
- 设计师都爱用的UI标注软件有哪些?
UI标注软件现在是设计师(UI.PM.前端等)必备的一款软件.设计稿是UI设计师日常工作中的产出物之一,当然,做出了高保真设计稿并不意味着你的工作结束了,因为你还得与下游的开发工程师进行对接. 我们经 ...
- jmeter对需要登录的接口进行性能测测试
只需要一步: https://www.testwo.com/blog/7253
- Vue单页面应用
单页面应用指一个系统只加载一次资源,然后下面的操作交互.数据交互是通过router.ajax来进 行,页面并没有刷新:<1>在vue搭建的环境里面怎么有没有公用的css和js? ...
- appium获取package和activity
输入命令adb shell dumpsys window w |findstr \/ |findstr name=然后在手机端打开app,电脑上按enter就即可显示 以微信为例子 appPackag ...
- Microsoft translater
professional tranlater tool : https://translator.microsoft.com/neural/