1121. Damn Single (25) map,set
来源:互联网 发布:西建大导师知乎 编辑:程序博客网 时间:2024/06/03 21:33
"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:311111 2222233333 4444455555 66666755555 44444 10000 88888 22222 11111 23333Sample Output:
510000 23333 44444 55555 88888
这题我记得当时考PAT乙的最后一题。。当时还不知道set,map。写的特别复杂。很多嵌套的循环(代码没保存,当时AC了,后面就没做)
用map建立关系,如果map【a】!=0,而且map[a]不存在set中,就是单身狗
或者说map【a】==0,肯定是单身狗
最后保存输出
#include<cstdio>#include<cmath>#include<algorithm>#include<iostream>#include<cstring>#include<queue>#include<vector>#include<set>#include<map>#include<stack>using namespace std;int main(){int n;cin>>n;map<int,int> m;for(int i=0;i<n;i++){ int a,b; cin>>a>>b; m[a+1]=b+1; m[b+1]=a+1;}int k;cin>>k;set<int> s;for(int i=0;i<k;i++){int num;cin>>num;num++;s.insert(num);} int flag=1;int out[100001],cnt=0; for(set<int>::iterator it=s.begin();it!=s.end();it++){int num=*it;if(m[num]==0){ out[cnt++]=num-1;}else{ if(s.find(m[num])!=s.end()){ continue;}else{out[cnt++]=num-1;}}} cout<<cnt<<endl;for(int i=0;i<cnt;i++){if(i==0) printf("%05d",out[i]);else printf(" %05d",out[i]);}return 0;}
- 1121. Damn Single (25) map,set
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- 1121. Damn Single (25)
- PAT--1121. Damn Single (25)
- A 1121. Damn Single (25)
- PAT_A 1121. Damn Single (25)
- PAT - 甲级 - 1121. Damn Single (25)
- 实训--day就算是23吧
- [LeetCode] Add One Row to Tree
- 浅谈zk(1) 为什么要使用zookeeper?
- [K叉哈夫曼树]BZOJ 4198—— [Noi2015]荷马史诗
- [机器学习入门] 李宏毅机器学习笔记-37 (Deep Reinforcement Learning;深度增强学习入门)
- 1121. Damn Single (25) map,set
- KendoUI:Grid控件的使用
- 小白教你学c++(7)一异常语法专题
- [编程之美-14]求二叉树中节点的最大距离
- TreeMap小应用
- python 学习笔记3
- 浅谈zk(2) zookeeper的特性
- 莫队(bzoj 2038: [2009国家集训队]小Z的袜子(hose))
- 上海家长给孩子择校的福利 虎妈家,一站式教育规划网站