codechef Cleaning Up 解决问题的方法
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 解决问题的方法的更多相关文章
- 解决问题的方法=>现象-->原因-->方案-->方案的优缺点
解决问题的方法=>现象-->原因-->方案-->方案的优缺点
- 访问 IIS 元数据库失败解决问题的方法
近日调试一Asp.net程序,出现了“访问 IIS 元数据库失败”的错误信息,最后经过搜索发现了解决问题的方法. 解决方法如下: 1.依次点击“开始”-“运行”. 2.在“运行”栏内输入 “C:\WI ...
- Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法
Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法
- Selenium私房菜系列9 -- 我遇到的问题及解决问题的方法
Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法
- NOIP 2012 解决问题的方法
[D1T1vigenerepassword] P1778vigenerepassword Accepted 标签:[显示标签] 描写叙述 16世纪法国外交家Blaise de Vigenère设计了一 ...
- POJ 3450 Corporate Identity KMP解决问题的方法
这个问题,需要一组字符串求最长公共子,其实灵活运用KMP高速寻求最长前缀. 请注意,意大利愿父亲:按照输出词典的顺序的规定. 另外要提醒的是:它也被用来KMP为了解决这个问题,但是很多人认为KMP使用 ...
- HDU 1251 统计拼图 Trie解决问题的方法
基本上找到一个标准前缀的问题是,只需要insert和search它功能. 这里的主要变化是我n该记录方法,这里n国旗代表的不是叶节点,但是话的标志这条道路后的数字. 然后找到需要找到一个词的前缀,假如 ...
- DB2 sql报错后查证原因与解决问题的方法
1.对于执行中的报错,可以在db2命令行下运行命令 : db2=>? SQLxxx 查看对应的报错原因及解决方法. 2.错误SQL0206N SQLSTATE=42703 检测到一个未定义的列 ...
- Python学习之--数字转人民币读法(解决问题的方法很重要)
效果图: 实现代码: money = float(input("Please input the money:"))cop = int(money)Num = ['零','壹',' ...
随机推荐
- RecordSet .CacheSize, Properties,CurserType,PageSize
使用 CacheSize 属性可以控制一次要从提供者那里将多少个记录检索到本地内存中.例如,如果 CacheSize 为 10,首次打开 Recordset 对象后,提供者将把前 10 个记录检索到本 ...
- python【第十四篇】HTML与CSS初遇
概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...
- QSslError 类
QSslError Class Header: #include <QSslError> qmake: QT += network Since: Qt 4.3 注意:这个类中的所有函数都是 ...
- Bluestacks 安卓模拟器利器
蓝手指测试安卓比较给力,尤其含有安卓原生态的多语言是现在厂商手机所无法提供了的. 但是有一点需要注意:BlueStack的日志文件非常大,日志目录默认是%Sysem Dir%/Program Da ...
- patchca整合Spring MVC生成超炫的验证码
转载:http://lavasoft.blog.51cto.com/62575/1406947 @Controller public class Login2Controller { priv ...
- [小知识]不显示没有内容的UITableViewCell
开发过程中常常使用到UITableView,当tableView的内容不足一屏时,若设置了talbeView的高度为屏幕高度,就会出现没有内容的cell显示出来,效果非常不好看,要想让没有内容的cel ...
- hduoj 1077 Catching Fish 求单位圆最多覆盖点个数
Catching Fish Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- [BZOJ 1058] [ZJOI2007] 报表统计 【平衡树】
题目链接:BZOJ - 1058 题目分析 这道题看似是需要在序列中插入一些数字,但其实询问的内容只与相邻的元素有关. 那么我们只要对每个位置维护两个数 Ai, Bi, Ai 就是初始序列中 i 这个 ...
- iOS7新特性-NSURLSession详解
前言:本文由DevDiv版主@jas 原创翻译,转载请注明出处!原文:http://www.shinobicontrols.com/b ... day-1-nsurlsession/ 大家都知道,过去 ...
- c printf
printf的格式控制的完整格式:% - 0 m.n l或h 格式字符下面对组成格式说明的各项加以说明:①%:表示格式说明的起始符号,不可缺少.②-:有-表示左对齐输出,如省略表示右对齐输出.③0:有 ...