码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1121 Damn Single


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

    1. 3
    2. 11111 22222
    3. 33333 44444
    4. 55555 66666
    5. 7
    6. 55555 44444 10000 88888 22222 11111 23333

    Sample Output:

    1. 5
    2. 10000 23333 44444 55555 88888
    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. int n, m, a[100010], x, y, b[100010], ans, cnt, c[100010];
    6. bool couple[100010], vis[100010];
    7. int main() {
    8. cin >> n;
    9. for (int i = 0; i < n; i++) {
    10. cin >> x >> y;
    11. a[x] = y;
    12. a[y] = x;
    13. couple[x] = 1;
    14. couple[y] = 1;
    15. }
    16. cin >> m;
    17. for (int i = 0; i < m; i++) {
    18. cin >> b[i];
    19. vis[b[i]] = 1;
    20. }
    21. for (int i = 0; i < m; i++) {
    22. if (!couple[b[i]]) { //本来就是单身
    23. c[cnt++] = b[i];
    24. } else {
    25. if (!vis[a[b[i]]]) {
    26. c[cnt++] = b[i]; //伴侣没来
    27. }
    28. }
    29. }
    30. sort(c, c + cnt);
    31. cout << cnt << endl;
    32. for (int i = 0; i < cnt; i++) {
    33. cout << setw(5) << setfill('0') << c[i];
    34. if (i != cnt - 1) {
    35. cout << ' ';
    36. }
    37. }
    38. return 0;
    39. }

     

  • 相关阅读:
    SpringBoot使用配置中心Apollo启动很慢两分钟解决
    隐私计算FATE-核心概念与单机部署
    昭通市鲁甸县卯家湾安置区:凝心聚力 共谱民族团结进步新篇章
    2023年11月12日阿里云产品全面故障的启示
    偶数科技入选 IDC 中国分布式数据库报告,获 Innovator 殊荣
    TI 毫米波雷达开发内容拆解分析
    面经 - 高频难
    【Java面试八股文宝典之基础篇】备战2023 查缺补漏 你越早准备 越早成功!!!——Day09
    【算法心得】minus instead of add
    关于初始化page入参的设计思路
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/127651658
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号