| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5792 人关注过本帖, 1 人收藏
标题:排班系统 c语言解法
只看楼主 加入收藏
天上第一把
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2017-3-2
结帖率:66.67%
收藏(1)
已结贴  问题点数:20 回复次数:7 
排班系统 c语言解法
学校实验楼有7名保安人员:钱、赵、孙、李、周、吴、陈。由于工作需要进行轮休制度,一星期中每人休息一天。预先让每一个人选择自己认为合适的休息日。请编制程序,打印轮休的所有可能方案。当然使每个人都满意,例如每人选择的休息日如下:
钱:星期一、星期六
赵:星期二、星期四
孙:星期三、星期日
李:星期五
周:星期一、星期四、星期六
吴:星期二、星期五
陈:星期三、星期六、星期日
搜索更多相关主题的帖子: 星期六 休息日 c语言 保安 
2017-03-05 20:00
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:4 
哦哦~第一直觉是用递归遍历所有可能解法~这是排列组合的变种~

最近到底怎么啦~虽然认真起上来会解~但九九懒敲代码了~


[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-03-05 21:36
烟雨晨曦
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:150
专家分:599
注 册:2017-3-5
收藏
得分:4 
#include <stdio.h>
int main(int argc, char** argv)
{
    int a[7] = {0};//数组表示7个人 值代表星期 0 开始
    for(int i = 0; i < 7; i++)
    {
        a[0] = i;
        for(int j = 0; j < 7; j++)
        {
            a[1] = j;
            for(int k = 0; k < 7; k++)
            {
                a[2] = k;
                a[3] = 4;
                for(int m = 0; m < 7; m++)
                {
                    a[4] = m;
                    for(int n = 0; n < 7; n++)
                    {   
                        a[5] = n;
                        for(int q = 0; q < 7; q++)
                        {
                            a[6] = q;
                            if(a[0] == a[1] || a[0] == a[2] || a[0] == a[3] || a[0] == a[4] || a[0] == a[5]
                                ||a[0] == a[6] || a[1] == a[2] || a[1] == a[3] || a[1] == a[4] || a[1] == a[5]
                                ||a[1] == a[6] || a[2] == a[3] || a[2] == a[4] || a[2] == a[5] || a[2] == a[6]
                                ||a[3] == a[4] || a[3] == a[5] || a[3] == a[6] || a[4] == a[5] || a[4] == a[6]
                                ||a[5] == a[6])
                            {
                                continue;
                            }
                            if(a[0] == 0 || a[0] == 5)
                            {
                                if(a[1] == 1 || a[1] == 3)
                                {
                                    if(a[2] == 2 || a[2] == 6)
                                    {
                                        if(a[3] == 4)
                                        {
                                            if(a[4] == 0 || a[4] == 3 || a[4] == 5)
                                            {
                                                if(a[5] == 1 || a[5] == 4)
                                                {
                                                    if(a[6] == 2 || a[6] == 5 || a[6] == 6)
                                                    {
                                                        for(int l = 0; l < 7; l++)
                                                        {
                                                            printf("%d ", a[l]);
                                                        }
                                                        printf("\n");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}


[此贴子已经被作者于2017-3-5 22:20编辑过]

2017-03-05 22:16
mnmn4429
Rank: 4
等 级:业余侠客
帖 子:64
专家分:245
注 册:2017-2-21
收藏
得分:4 
回复 3楼 烟雨晨曦
好程序
2017-03-05 22:27
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
回复 3楼 烟雨晨曦
把人数改成70就笑了~~
不过九九也认为这是一个好程序~~


[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-03-06 06:55
烟雨晨曦
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:7
帖 子:150
专家分:599
注 册:2017-3-5
收藏
得分:0 
回复 5楼 九转星河
//递归大概是这样吧
void Travel(int n, int* a)
{
    for(int i = 0; i < 7; i++)
    {
        a[n] = i;
        Travel(int n, int* a);
        if(n == 0)
        {
               //判断条件
        }
    }
}
2017-03-06 11:31
九转星河
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:长长久久
等 级:贵宾
威 望:52
帖 子:5023
专家分:14003
注 册:2016-10-22
收藏
得分:0 
回复 7楼 烟雨晨曦
思路应该没有问题~就是感觉要用二维数组~

[code]/*~个性签名:bug是什么意思?bug是看上去没有可能的东西实际上是有可能做到的 就是这样~2018-08-08更~*/[/code]
2017-03-06 13:05
cdmalcl
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:4091
专家分:524
注 册:2005-9-23
收藏
得分:4 
手头没C环境 图省事儿用JS写个,至少很容易看明白思路:
程序代码:
clear();

var _eWeek = ['', '', '', '', '', '', ''];

function initData(){
    var peoples = [];
    peoples[0] = {cnFirstName:''};
    peoples[1] = {cnFirstName:''};
    peoples[2] = {cnFirstName:''};
    peoples[3] = {cnFirstName:''};
    peoples[4] = {cnFirstName:''};
    peoples[5] = {cnFirstName:''};
    peoples[6] = {cnFirstName:''};

    var wantsData = [];
    wantsData[0] = [];
    wantsData[0][0] = 1;
    wantsData[0][1] = 6;
    wantsData[1] = [];
    wantsData[1][0] = 2;
    wantsData[1][1] = 4;
    wantsData[2] = [];
    wantsData[2][0] = 3;
    wantsData[2][1] = 0;
    wantsData[3] = [];
    wantsData[3][0] = 5;
    wantsData[4] = [];
    wantsData[4][0] = 1;
    wantsData[4][1] = 4;
    wantsData[4][2] = 6;
    wantsData[5] = [];
    wantsData[5][0] = 2;
    wantsData[5][1] = 5;
    wantsData[6] = [];
    wantsData[6][0] = 3;
    wantsData[6][1] = 6;
    wantsData[6][2] = 0;
    return {wantsData:wantsData, peoples:peoples};
}

function getAllTrun(peoples, wantsData){
    var turn = [];
    var last = [];
    var bOver = false;
    var limit = 0;
    while (true){
        if (limit++ > 1000000){    // 可去掉
            break;
        }
        for (var t in wantsData){
            if (typeof wantsData[t] != 'object'){
                continue;
            }
            if (last[t] >= 0){
            }else{
                last[t] = 0;
            }
            for (var l=t; l>=0; l--){
                if (wantsData[l].length <= last[l]){
                    last[l] = 0;
                    if (l == 0){
                        bOver = true;
                        break;
                    }else{
                        last[l-1] ++;
                    }
                }    
            }
        }
        if (bOver){
            break;
        }
        var unit = [];
        var weekStat = [];    // 统计每天有几个人休息,如果限制当天不能全休息可以通过此数据判断
        for (var t in wantsData){
            if (typeof wantsData[t] != 'object'){
                continue;
            }
            var w = wantsData[t][last[t]];
            if (weekStat[_eWeek[w]] > 0)
                weekStat[_eWeek[w]] ++;
            else
                weekStat[_eWeek[w]] = 1;
            unit.push({week:w, people:t, stat:weekStat});
        }

        last[t] ++;
        turn.push(unit);
    }
    return turn;
}
var data = initData();
var all = getAllTrun(data.peoples, data.wantsData);

// test 
for (var a in all){
    var unit = [];
    for (var t in all[a]){
        unit.push("星期"+_eWeek[all[a][t].week]+":"+peoples[all[a][t].people].cnFirstName);
    }
    console.log(unit.join(","));
}
2017-03-06 17:29
快速回复:排班系统 c语言解法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023390 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved