Codechef cleaning up how to solve problems

Source: Internet
Author: User

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

most of the cooks has already left and only the Chef, and his assistant is left-to-clean up. Thankfully, some of the cooks took care of some of the the jobs before they left so only a subset of the n jobs remain. The Chef and his assistant divide to 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, TH E Chef takes the unfinished job with the third least index, etc. That's, if the unfinished jobs were listed in increasing order of their index then the Chef would take every other one St Arting with the first job, the list and the assistant would take every, and the starting job on the List.

The cooks logged which jobs they finished before they left. Unfortunately, these jobs were not recorded on any particular order. Given an unsorted list
Of finished jobs, you is to determine which jobs the Chef must complete and which jobs he assitant must complete before Closing the kitchen for the
Evening.

Example
Input:4 8Output:3 6511 4 62 5 7

Simple classification of the topic.

With a bool type, it is possible to take turns simulating the election of 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;}


Copyright notice: The author Jing Heart, King Space address: http://blog.csdn.net/kenden23/, only after the author agreed to reprint.

Codechef cleaning up How to troubleshoot problems

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.