码迷,mamicode.com
首页 > 其他好文 > 详细

codechef Cleaning Up 解决问题的方法

时间:2015-10-23 20:09:33      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:

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


版权声明:笔者靖心脏,景空间地址:http://blog.csdn.net/kenden23/,只有经过作者同意转载。

codechef Cleaning Up 解决问题的方法

标签:

原文地址:http://www.cnblogs.com/hrhguanli/p/4905501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!