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; }
codechef Cleaning Up 题解,布布扣,bubuko.com