• 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. }

     

  • 相关阅读:
    DDD领域驱动设计-子域
    flask 支付宝的使用
    glsl语法之变量限定符
    Kmssink插件添加缩放显示功能的分析思路与具体实现
    复杂微纳结构制造需求旺盛 微纳3D打印市场发展前景广阔
    Spring 中如何为Bean注入集合呢?
    如何在SpringBoot中定义一个自定义的Starter?
    一分钟学习数据安全——自主管理身份SSI基本概念
    MyBatis-Plus动态表名插件使用
    浅说一维数组以及遍历,length函数
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/127651658