codechef Cleaning Up 题解

After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n.

Most of the cooks have already left and only the Chef and his assistant are left to clean up. Thankfully, some of the cooks took care of some of the jobs before they left so only a subset of the n jobs remain. The Chef and his assistant divide up the remaining jobs in the following manner. The Chef takes the unfinished job with least index, the assistant takes the unfinished job with the second least index, the Chef takes the unfinished job with the third least index, etc. That is, if the unfinished jobs were listed in increasing order of their index then the Chef would take every other one starting with the first job in the list and the assistant would take every other one starting with the second job on in the list.

The cooks logged which jobs they finished before they left. Unfortunately, these jobs were not recorded in any particular order. Given an unsorted list
of finished jobs, you are to determine which jobs the Chef must complete and which jobs his assitant must complete before closing the kitchen for the
evening.

Example

Input:
3
6 3
2 4 1
3 2
3 2
8 2
3 8

Output:
3 6
5
1

1 4 6
2 5 7

 简单的分类题目了。

使用一个bool型,轮流模拟选jobs就可以了。

#pragma once
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <stdio.h>
#include <iostream>
using namespace std;

int CleaningUp()
{
	int T, n, m, j = 0;
	cin>>T;

	while (T--)
	{
		cin>>n>>m;
		bool finJobs[1001] = {0};
		vector<int> chefJobs, assiJobs;
		for (int i = 0; i < m; i++)
		{
			scanf("%d", &j);
			finJobs[j] = true;
		}
		bool turn = true;
		for (int i = 1; i <= n; i++)
		{
			if (!finJobs[i])
			{
				if (turn) chefJobs.push_back(i);
				else assiJobs.push_back(i);
				turn = !turn;
			}
		}
		for (int i = 0; i < (int)chefJobs.size(); i++)
		{
			printf("%d ", chefJobs[i]);
		}
		putchar('\n');
		for (int i = 0; i < (int)assiJobs.size(); i++)
		{
			printf("%d ", assiJobs[i]);
		}
		putc('\n', stdout);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值