博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1121 Damn Single【25】
阅读量:4542 次
发布时间:2019-06-08

本文共 2284 字,大约阅读时间需要 7 分钟。

"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:

311111 2222233333 4444455555 66666755555 44444 10000 88888 22222 11111 23333

Sample Output:

510000 23333 44444 55555 88888 使用couple记录是否有配偶 使用flag标记是否配偶到场 注意:最后不要输出换行,不然一旦没有输出,那么就有两个换行了!
1 #include 
2 #include
3 using namespace std; 4 int main() 5 { 6 int n, m, boy, girl, id; 7 int couple[100005], flag[100005]; 8 set
guests, res; 9 cin >> n;10 fill(couple, couple + 100005, -1);11 fill(flag, flag + 100005, 0);12 while (n--)13 {14 cin >> boy >> girl;15 couple[boy] = girl;16 couple[girl] = boy;17 }18 cin >> m;19 while (m--)20 {21 cin >> id;22 guests.insert(id);23 if (couple[id] == -1)24 continue;25 else if (flag[id] == 0)//对偶没有来26 {27 flag[id] = 1;28 flag[couple[id]] = 1;29 }30 else if (flag[id] == 1)//对偶来了31 {32 flag[id] = -1;33 flag[couple[id]] = -1;34 }35 }36 for (auto a : guests)37 {38 if (flag[a] != -1)39 res.insert(a);40 }41 cout << res.size() << endl;42 for (auto a : res)43 printf("%s%05d", (a == *(res.begin()) ? "" : " "), a);44 return 0;45 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11470141.html

你可能感兴趣的文章
如何简单解释 MapReduce算法
查看>>
面向接口编程详解(二)——编程实例
查看>>
解决java.lang.NoClassDefFoundError: org/apache/log4j/Level
查看>>
端口号
查看>>
mysql for macOS安装
查看>>
HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
查看>>
语言基础
查看>>
C# : 操作Word文件的API - (将C# source中的xml注释转换成word文档)
查看>>
C#中字符串转换成枚举类型的方法
查看>>
Airplace平台
查看>>
TinyOS实例介绍
查看>>
我是怎么定义微服务平台?
查看>>
python random
查看>>
input输入框只允许输入数字/ 数字+小数点/ 文字+字母/ 等解决方法
查看>>
【翻译】西川善司「实验做出的游戏图形」「GUILTY GEAR Xrd -SIGN-」中实现的「纯卡通动画的实时3D图形」的秘密,前篇(2)...
查看>>
mysql 5.6 参数详解
查看>>
求旋转数组的最小元素
查看>>
Gson解析Json数组
查看>>
Lintcode: Fast Power
查看>>
Pocket Gem OA: Log Parser
查看>>