【1121】Damn Single (25分)【set】

简介: 【1121】Damn Single (25分)【set】【1121】Damn Single (25分)【set】
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue>
#include<set>
using namespace std;  
//此题单身狗的定义为没老婆或老婆没来
//重点是isExist数组的灵活运用
int main(){   
  int n;//n对夫妻
  int m;//m人参加party
  scanf("%d",&n);//夫妻数
  vector<int>couple(100000);
  for(int i=0;i<100000;i++)
    couple[i]=-1;
  int a,b;//接受一对夫妻
  for(int i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    couple[a]=b;
    couple[b]=a;
  }
  scanf("%d",&m);
  vector<int>guest(m);//来宾数组
  vector<int>isExist(100000);
    vector<int>havewife(100000);
  //表示某人的对象是否来到了排队上
  for(int i=0;i<m;i++){
    scanf("%d",&guest[i]);
    if(couple[guest[i]] !=-1)//如果非单身(我)
      isExist[couple[guest[i]]]=1;
      //我女票的男票(即我)来了,这句最神奇!!!
  }
  set<int>s;
  for(int i=0;i<m;i++)
    if(!isExist[guest[i]])    
      s.insert(guest[i]);
  printf("%d\n",s.size());
  for(auto it=s.begin();it!=s.end();it++){
    if(it !=s.begin())  printf(" ");
    printf("%05d",*it);
  }
  system("pause");
    return 0;   
}
相关文章
|
11月前
new Set与...new Set()的区别
new Set与...new Set()的区别,妙用多多
99 0
|
算法
LeetCode 260. Single Number III
给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。
75 0
LeetCode 260. Single Number III
|
存储 测试技术
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
91 0
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
81 0
PAT (Advanced Level) Practice - 1039 Course List for Student(25 分)
PAT (Advanced Level) Practice - 1039 Course List for Student(25 分)
75 0
|
存储
PAT (Advanced Level) Practice - 1051 Pop Sequence(25 分)
PAT (Advanced Level) Practice - 1051 Pop Sequence(25 分)
83 0
【1113】Integer Set Partition (25分)
【1113】Integer Set Partition (25分) 【1113】Integer Set Partition (25分)
86 0
【1063】Set Similarity (25 分)
【1063】Set Similarity (25 分) 【1063】Set Similarity (25 分)
78 0
【1144】The Missing Number (20 分)
【1144】The Missing Number (20 分) 【1144】The Missing Number (20 分)
69 0

热门文章

最新文章