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;
}