修复bug,完成基本逻辑

This commit is contained in:
jsh
2025-10-11 20:45:59 +08:00
parent 674de604e8
commit 5d9a5dda10
4 changed files with 44 additions and 27 deletions

1
.idea/encodings.xml generated
View File

@@ -2,5 +2,6 @@
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

2
.idea/misc.xml generated
View File

@@ -8,5 +8,5 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" project-jdk-name="21" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="19" project-jdk-type="JavaSDK" />
</project>

View File

@@ -4,6 +4,7 @@ import com.dota.domain.Doctor;
import com.dota.domain.Week;
import com.dota.domain.WorkEnum;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
@@ -15,6 +16,11 @@ public class Main {
static Doctor zh;
static Doctor tgy;
// 日期
static int days = 0;
// 医生下标
static int idx = 0;
public static void main(String[] args) {
init();
var doctorOrder = new Doctor[]{
@@ -56,15 +62,9 @@ public class Main {
}
static void schedule(Doctor[] doctors, Doctor[] outputOrder) {
// 日期
int days = 0;
// 医生下标
int idx = 0;
for (int k = 0; k < 2; k++) {
for (int i = 0; i < 7; i++) {
var d = doctors[idx];
if (d.firstRest) {
d.firstRest = false;
d.works[0] = WorkEnum.HOLIDAY;
@@ -92,7 +92,7 @@ public class Main {
}
days = (days + 1) % 7;
idx = (idx + 1) % doctors.length;
idx = (idx + 1) % 6;
}
fix(doctors);
@@ -104,28 +104,45 @@ public class Main {
}
}
record Rest(int day, int cnt) {
}
// 给有调休的安排休息
// 保证同一组必须有一个在
static void rest(Doctor[] doctors) {
var list = new ArrayList<Rest>();
for (int i = 0; i < 5; i++) {
list.add(new Rest(i, 0));
}
for (Doctor doctor : doctors) {
if (doctor.lastRestCount == 0) {
continue;
}
int count = 0;
for (int j = 0; j < 5; j++) {
if (checkRest(j, doctor, doctors)) {
doctor.works[j] = WorkEnum.REST;
count++;
}
if (count==doctor.lastRestCount) {
break;
for (int i = 0; i < 5; i++) {
if (doctor.works[i] == WorkEnum.DUTY || doctor.works[i] == WorkEnum.WORK) {
list.set(i, new Rest(i, list.get(i).cnt + 1));
}
}
}
list.sort((a, b) -> b.cnt - a.cnt);
for (Doctor doctor : doctors) {
doctor.lastRestCount = doctor.restCount;
if (doctor.restCount == 0) {
continue;
}
int i = 0;
int j = 0;
while (i < doctor.restCount) {
Rest r = list.get(j++);
if (checkRest(r.day, doctor, doctors)) {
j = 0;
doctor.works[r.day] = WorkEnum.REST;
i++;
list.add(new Rest(r.day, r.cnt - 1));
list.remove(r);
list.sort((a, b) -> b.cnt - a.cnt);
}
}
}
}

View File

@@ -2,9 +2,7 @@ package com.dota.domain;
public class Doctor {
public String name;
// 周的调休
public int lastRestCount;
// 下周的调休
// 周五六日值班的调休
public int restCount = 0;
// 门诊时间
@@ -34,6 +32,7 @@ public class Doctor {
}
public void reset() {
this.restCount = 0;
for (int i = 0; i < 5; i++) {
works[i] = WorkEnum.WORK;
}
@@ -44,8 +43,8 @@ public class Doctor {
switch (name) {
case "周晖" -> works[1] = WorkEnum.OPD;
case "唐婷婷" -> works[2] = WorkEnum.OPD;
case "李宁" -> works[3] = WorkEnum.OPD;
case "章亮" -> works[4] = WorkEnum.OPD;
case "李宁" -> works[4] = WorkEnum.OPD;
case "章亮" -> works[3] = WorkEnum.OPD;
}
}