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 解决问题的方法的更多相关文章

  1. 解决问题的方法=>现象-->原因-->方案-->方案的优缺点

    解决问题的方法=>现象-->原因-->方案-->方案的优缺点

  2. 访问 IIS 元数据库失败解决问题的方法

    近日调试一Asp.net程序,出现了“访问 IIS 元数据库失败”的错误信息,最后经过搜索发现了解决问题的方法. 解决方法如下: 1.依次点击“开始”-“运行”. 2.在“运行”栏内输入 “C:\WI ...

  3. Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

    Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

  4. Selenium私房菜系列9 -- 我遇到的问题及解决问题的方法

    Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法

  5. NOIP 2012 解决问题的方法

    [D1T1vigenerepassword] P1778vigenerepassword Accepted 标签:[显示标签] 描写叙述 16世纪法国外交家Blaise de Vigenère设计了一 ...

  6. POJ 3450 Corporate Identity KMP解决问题的方法

    这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用 ...

  7. HDU 1251 统计拼图 Trie解决问题的方法

    基本上找到一个标准前缀的问题是,只需要insert和search它功能. 这里的主要变化是我n该记录方法,这里n国旗代表的不是叶节点,但是话的标志这条道路后的数字. 然后找到需要找到一个词的前缀,假如 ...

  8. DB2 sql报错后查证原因与解决问题的方法

    1.对于执行中的报错,可以在db2命令行下运行命令 : db2=>? SQLxxx 查看对应的报错原因及解决方法. 2.错误SQL0206N SQLSTATE=42703  检测到一个未定义的列 ...

  9. Python学习之--数字转人民币读法(解决问题的方法很重要)

    效果图: 实现代码: money = float(input("Please input the money:"))cop = int(money)Num = ['零','壹',' ...

随机推荐

  1. PHPCMS标签:PC标签模板语法规则

    模板语法规则1.变量表示{$name} 被解析成 <?=$name?>,表示显示变量$name的值,其中的“name”由英文字母.数字和下划线组成首字母必须是英文字母或者下划线. 2.常量 ...

  2. C# Winform开发框架企业版V4.0新特性

    企业版V4.0 - 新特性 C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4. ...

  3. 在oj平台上练习的一些总结【转】

    程序书写过程中的一些小技巧:1. freopen(“1.txt”,”r”,stdin); //程序运行后系统自动输入此文档里面的内容(不需要进行手动输入)freopen(“1.txt”,”w”,std ...

  4. PR曲线平滑

    两天写论文中,本来设计的是要画这个Precision-Recall Curve的,因为PRC是从信息检索中来的,而且我又做的类似一个检索,所以要画这个图,但是我靠,竟然发现不好画,找了很多资料等.最后 ...

  5. 使用Autofac部署IIS6.0时未能加载文件或程序集“System.Core, Version=2.0.5.0...“

    错误信息 .net4.0项目中使用autofac这个IOC容器,在部署在win2003+iis6时出现以下错误. “/”应用程序中的服务器错误. --------------------------- ...

  6. xfire实现webservice客户端之测试关注点

    日前的工作接触到很多系统间的Webservice调用,这里想谈谈基于spring+xfire实现的webservice的客户端踩过的一些坑,需要测试关注的点. xFire的配置项 在spring中实现 ...

  7. CSS font-family的順序

    2016年09月07日 13時51分 wanglinqiang整理 相信大家都知道基本的用法是這樣: font-family:font1,font2,serif; 系統有font1就先用font1 如 ...

  8. OpenJudge_cdqz 数据结构版块小结

    题目整理 Challenge 0  随机线性存储表-easy Challenge 1  链表数组-easy Challenge 2  可持久化Treap的可持久化运用-hard Challenge 3 ...

  9. Fibonacci Tree

    hdu4786:http://acm.hdu.edu.cn/showproblem.php?pid=4786 题意:给你一个无向图,然后其中有的边是白色的有的边是黑色的.然后问你是否存在一棵生成树,在 ...

  10. css3图片墙

    css相关知识: 1. 使用box-shadow设置图片阴影,为照片加上阴影 eg: box-shadow: 0 0 5px 3px #abc 2. 使用tansform-origin定义变形原点 e ...