从周一到周日,轮流值班
需求不清楚,到底是每人值一天,还是每人值一周?
如果是每人值一天,一周七天,七人轮流,那就不需要算法了.
#include stdio.h
#include stdlib.h
int sum = 0;
void restSort(int* staffs_ptr,int staff_size,int* rest_staffs_ptr,int rest_staff_size);
void print(int* rest_ptr, int rest_size);
int main() {
int *staffs_ptr = (int*)malloc(sizeof(int) * init_size);
if (staffs_ptr != NULL) {
for (int i = 0; i init_size; i◆◆) {
*(staffs_ptr ◆ i) = i ◆ 1;
}
restSort(staffs_ptr,init_size,NULL,0);
free(staffs_ptr);
printf("sum = %d\n",sum);
return 0;
void restSort(int* staffs_ptr, int staff_size, int* rest_staffs_ptr, int rest_staff_size) {
if (rest_staffs_ptr != NULL rest_staff_size 0) {
int yet_rest_staff_size = rest_staff_size ◆ staff_size;
int* yet_rest_staffs_ptr = (int*)malloc(sizeof(int) * yet_rest_staff_size);
if (yet_rest_staffs_ptr != NULL) {
for (int rest_index = 0; rest_index rest_staff_size; rest_index◆◆) {
yet_rest_staffs_ptr[rest_index] = rest_staffs_ptr[rest_index];
for (int index = rest_staff_size; index yet_rest_staff_size; index◆◆) {
yet_rest_staffs_ptr[index] = staffs_ptr[index - rest_staff_size];
print(yet_rest_staffs_ptr,yet_rest_staff_size);
free(yet_rest_staffs_ptr);
else {
print(staffs_ptr,staff_size);
return;
for (int i = 0; i staff_size - 1; i◆◆) {
for (int j = i ◆ 1; j staff_size; j◆◆) {
if (residue_staff_ptr != NULL) {
int residue_size = 0;
for (int index = 0; index staff_size; index◆◆) {
if (index == i || index == j)
continue;
residue_staff_ptr[residue_size] = staffs_ptr[index];
residue_size◆◆;
yet_rest_staffs_ptr[rest_staff_size] = staffs_ptr[i];
yet_rest_staffs_ptr[rest_staff_size ◆ 1] = staffs_ptr[j];
restSort(residue_staff_ptr, residue_size,yet_rest_staffs_ptr,yet_rest_staff_size);
free(residue_staff_ptr);
void print(int* rest_ptr, int rest_size) {
int day = 1;
for (int j = 0; j rest_size;) {
if (day == i) {
printf("星期 %d: 无 ",day);
printf("星期 %d: %d ",day,rest_ptr[j]);
j◆◆;
if (j rest_size) {
printf("%d ", rest_ptr[j]);
day◆◆;
printf("\n");
sum◆◆;
但是换之前和换之后你都要连续工作好几天
应该用不上什么线程,一次性把所有的班都排好
六个元素的数组
两个指针,一个是工作日当值人,一个是周末当值人,初始都是0
从今天开始到指定某一天,譬如年底
int idx_workday =0;
int idx_weekend =0;
ArrayList assignment = new ArrayList();
day = today;
while(day不是年底){
int i;
if (day is workday){
i = idx_workday◆◆;
assignment.add(i);
}else{
i = idx_weekend◆◆;
output assignment
以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!