1065 单身狗 (25分)

cp[100000] —— 用来记录cp

cp[c1] = c2;

cp[c2] = c1;

yes[100000] —— 用来标记来客是否到场

遍历一下,若该客人有cp且cp到场,将yes[该客人]、yes[该客人cp]都置为0

再输出yes为0的值

#include<iostream>
#include<algorithm>
using namespace std;

int main() {
	int cp_count, total;
	int i, j;
	int sum = 0;
	cin >> cp_count;
	int c1, c2;
	j = 0;
	int cp[100000] = { 0 };
	for (i = 0; i < cp_count; i++) {
		cin >> c1 >> c2;
		cp[c1] = c2;
		cp[c2] = c1;
	}
	cin >> total;
	int* guest = new int[total];
	int yes[100000] = { 0 };
	for (i = 0; i < total; i++) {
		cin >> guest[i];
		yes[guest[i]] = 1;
	}
	for (i = 0; i < total; i++) {
		int temp = guest[i];
		int couple = cp[temp];
		if (couple != 0 && yes[couple] == 1) { //这个客人有情侣且情侣也在场
			yes[couple] = 0;
			yes[temp] = 0;
		}
		else {
			sum++;
		}
	}
	j = 0;
	int* ans = new int[sum];
	for (i = 0; i < total; i++) {
		int temp = guest[i];
		if (yes[temp] == 1) {
			ans[j++] = temp;
		}
	}
	cout << j << endl;
	sort(ans, ans + j);
	for (i = 0; i < j; i++) {
		printf("%05d",ans[i]);
		if (i < j - 1) { printf(" "); }
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值