• 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('
    ');
    		for (int i = 0; i < (int)assiJobs.size(); i++)
    		{
    			printf("%d ", assiJobs[i]);
    		}
    		putc('
    ', stdout);
    	}
    	return 0;
    }


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

  • 相关阅读:
    代理类和装饰类的区别
    spring mvc 处理映射的几种方式
    如何深入浅出的理解跳转方式:重定向和请求转发
    springMVC拦截配置
    ※版本管理※=>☆SVN工具=>※解决地域麻烦※№→搭建自己的网络SVN (SourceForge 免费) [转]
    权力社会? 金钱社会? 透过现象看本质-让权力和金钱的力量沿着制度的河道流淌,才是社会稳定的基石
    自己封装的CMusic类 【转】
    VC++中MCI播放音频文件 【转】
    DevExpress.XtraGrid 【转】
    C# Process.Start()方法详解 [转]
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4905501.html
Copyright © 2020-2023  润新知