- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有点愚蠢的问题,但很有趣,在我看来,它应该是一个“已解决的问题”。我主要只是对算法感兴趣,我可以自己处理实现。
规范是:
users = [
"Alice",
"Bob",
"Carl",
"Dani",
"Elmer",
]
chores = [
"Kitchen",
"Dining room",
"Upstairs bathroom",
"Living room",
"Lawn",
]
exclusion_list = [
("Bob", "Upstairs bathroom")
]
weekly_offset = 0
# Generate a list of chores "doable" by each user
# Horrible method I know, but just trying to get something working
# and for trivial n and m it shouldn't matter.
user_list = {}
for i in users:
temp_list = []
for j in chores:
for k in exclusion_list:
if k[0] == i and k[1] == j:
print("Excluded")
else:
temp_list.append(j)
user_list[i] = temp_list
# Confirm this list is accurate
print(user_list)
print()
user_offset = 0
for i in user_list:
print(i, end = ": ")
chore_index = (weekly_offset + user_offset) % len(user_list[i])
print(user_list[i][chore_index])
user_offset += 1
最佳答案
The specs are:
Assume a house of n people.
Assume m chores.
For now, for simplicity's sake, assume n == m.
Assume an exclusion list of tuple, ie, Bob doesn't have to ever clean the upstairs bathroom since he lives in a different part of the house, with his own private bathroom. He is however responsible for the other chores.
Assume a "weekly offset" integer variable that is incremented on disk. If this variable is not incremented, the program spits out the same output each time. For now, I'm simply incrementing this variable manually.
No two people should be assigned the same chore for a given week.
Each person should do "each chore they are capable of doing" exactly once before repeating a chore.
exclusion_list
,即第四个条件。
exclusion_list
,一种可能的解决方案如下:
# Abbreviations:
# K == "Kitchen", D == "Dining room", U == "Upstairs bathroom"
# Lr == "Living room", L == "Lawn"
Week 1 2 3 4 5
Alice: K -> D -> U -> Lr -> L
Bob: D -> U -> Lr -> L -> K
Carl: U -> Lr -> L -> K -> D
Dani: Lr -> L -> K -> D -> U
Elmer: L -> K -> D -> U -> Lr
exclusion_list
, Bob 应该有一个长度为 4 的链。这意味着 Bob 将在 5 周内完成 4 项不同的家务活,如下所示:
Week 1 2 3 4 5
Bob: D -> Lr -> L -> K -> D
(5 kinds of chores) * (5 weeks) = 25
要做的家务。并且,由于其他 4 个用户将在 5 周内做 5 种不同类型的家务(因为他们应该有一个长度为 5 的链),分配给 4 个用户后剩余的家务数量为
25 - ((5 kinds of chores) * (4 users)) = 25 - 20 = 5
.这 5 件家务活都是不同的种类。
它与 相矛盾Bob 应该有一个长度为 4 的链。
users = [
"Alice",
"Bob",
]
chores = [
"Kitchen",
"Dining room",
]
exclusion_list = [
("Bob", "Kitchen")
]
关于algorithm - 为家庭创造一个家务轮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61945445/
我在创建/理解 promise 方面遇到了困难。我了解它们的优点并了解如何使用它们。创建自己的 promise 功能是困难的部分。简单地说,如何将此函数转换为与 Promise 一起使用: ret.g
这是我以前的question的跟进 假设我想用我的函数创建一个future,但是不想立即启动它(即我不想调用val f = Future { ... // my function}。 现在,我可以看到
使用以下函数表示从本地 html 文件生成 Web 存档 function TLessonConstructor2.CreateMHT( const FileName : string):boolea
我正在研究注册安全。 @RestController public class UserController { @Autowired private BCryptPasswordEncoder bC
在下面的示例代码中,我想创建一个 Item来自 Component 的对象: struct Component { }; struct Item { explicit Item(Compone
我有以下代码。我认为通过发布我可以创建一个热流,但是每个连接上的 uniqueId 都不同。我希望 create 方法执行一次,然后作为任意数量的订阅者的热流运行。 private Date
我有以下型号 type User struct { gorm.Model Languages []Language `gorm:"many2many:user_language
我想做的是用管道创建这种通信: 1 / \ 3 2 \ / 4 所以应该有3个 child 。 parent 给第一个和第二个 child
我正在将一些代码从 Win32 移植到使用锁定文件的 Linux。我用 open 为 Linux 做了一个实现,但我不确定如果文件在 Samba 共享上它是否会工作。我试过了,它似乎可以正常工作,但我
我是一名优秀的程序员,十分优秀!