Codechef Cleaning Up question

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.