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 (≤ 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

嗯...水 不过自己wa了一次就是

我使用mp 但是里面也可能出现的00000也就是0 这种情况啊  这种情况下我会当成他是条单身狗

这个是有问题的嗯.............稍微修改了下

代码:

#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
vector<int>vec,vv;
bool cmp(int a,int b){return a<b;
}
int main()
{int n,a,b;scanf("%d",&n);for(int i =1 ;i<=n;i++){scanf("%d%d",&a,&b);if (a==0) a=111111;else if(b==0) b =111111;mp[a] = b;mp[b] = a;}int k ;scanf("%d",&k);for(int i = 1 ;i<=k;i++){scanf("%d",&a);if(a==0)a=111111;vec.push_back(a);}for(int i = 0;i < k;i++){if(mp[ vec[i] ] == 0)vv.push_back(vec[i]);//本身就是单身狗 else {if(count(vec.begin(),vec.end(),mp[ vec[i] ]) == 0)//在这个聚会上找不到配偶 vv.push_back(vec[i]);  }   }printf("%d\n",vv.size());sort(vv.begin(),vv.end(),cmp);if(count(vv.begin(),vv.end(),111111)==1){vv.erase(vv.end()-1);vv.push_back(0);}sort(vv.begin(),vv.end(),cmp);for(int i = 0; i < vv.size(); i++)printf("%05d%c",vv[i]," \n"[i==vv.size()-1]);return 0;
}

1121 Damn Single(25 分)相关推荐

  1. 1121 Damn Single (25分)

    1121 Damn Single (25分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bein ...

  2. 1121. Damn Single (25)

    1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...

  3. PAT甲级 1121. Damn Single (25)

    1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...

  4. 1121. Damn Single (25)-PAT甲级真题

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  5. 【PAT】1121. Damn Single (25)【哈希表】

    题目描述 "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are ...

  6. 1121 Damn Single (25 分)

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  7. PAT——1121 Damn Single 甲级

    1121 Damn Single 题目 题意 代码解析 AC代码 参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/99 ...

  8. PAT 甲级 1121  Damn Single

    1121 Damn Single (25 point(s)) "Damn Single (单身狗)" is the Chinese nickname for someone who ...

  9. 12门课100分直博清华!这份成绩单冲上热搜,但学霸小伙也曾考过25分

    点击上方"视学算法",选择加"星标"或"置顶" 重磅干货,第一时间送达 金磊 明敏 发自 凹非寺 量子位 报道 | 公众号 QbitAI 一 ...

  10. PTA 7-3 旅游规划 (25分)(双权值Dijkstra最短路)

    7-3 旅游规划 (25分) 有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路 ...

最新文章

  1. windows磁盘分区
  2. Redis集群研究和实践(基于redis 3.0.5)
  3. apache 服务器概述--安装(一)
  4. 面状县级行政区划转地级行政区划,并关联属性字段
  5. [云炬创业基础笔记]第六章商业模式测试14
  6. boost::describe模块实现计算基础修饰符的测试程序
  7. ASP.NET状态管理
  8. MS Script Control的 COM
  9. 进入REST Core
  10. Facebook全面实施GDPR 用户Pages页面被随意锁定
  11. [计算机组成原理-02] 计算机硬件的基本组成和工作原理
  12. Autodesk Eagle入门之-开启旅程
  13. 用思科模拟器对交换机进行超级终端配置和Telnet远程登录配置
  14. CBA离好生意还差几个NBA?
  15. 计算过去某天距离今天过去了多少天。
  16. 3D游戏:八、粒子系统与流动效果
  17. Mongo入门-2-基本操作
  18. 实际参数与形式参数的区别
  19. 女生学计算机类还是电子信息类好,电子信息类专业的女生即将面临大二专业分流,电子信息、通信和光电信息科学与工程选哪个好?为什么?...
  20. vue 使用cesium

热门文章

  1. python3种基本数字类型_Python3基本数据类型
  2. python 构建来源gis_Python语言在ArcGIS环境中的应用.pptx
  3. Java经典设计模式(1):五大创建型模式(附实例和详解)
  4. maven 下载不到jar包时候,更改阿里源
  5. Scrum vs Waterfall vs Agile vs Lean vs Kanban
  6. Date实战案例:倒计时日历
  7. inux系统磁盘管理基础知识及总结
  8. Centos6.5 x86_64系统安装kvm虚拟机—基础篇
  9. Nginx监控数据采集与分析
  10. ehcache缓存共享(rmi方法)