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 wocould take every other one starting with the first job in the list and the assistant wocould 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 participant 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
Evening.
Example
Input:36 32 4 13 23 28 23 8Output:3 6511 4 62 5 7
A simple classification question.
A bool type is used to simulate and select jobs in turn.
#pragma once#include
#include
#include #include
#include
#include
using namespace std;int CleaningUp(){int T, n, m, j = 0;cin>>T;while (T--){cin>>n>>m;bool finJobs[1001] = {0};vector
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;}