我想编写一个 C 程序来解决下面给出的数学问题,但我做不到。如果有人能做到这一点,我将不胜感激? 一个农民有 81 头奶牛,编号为 1 到 81。没有 1 头奶牛每天产 1 公斤牛奶……没有 2 头奶牛每天产奶 2 公斤……没有 81 头奶牛每天产奶 81 公斤。农民有9个儿子。现在他想把他的奶牛分配给他的儿子们,每个儿子拿9头奶牛,牛奶总量相同。他如何分配?
最佳答案
不涉及太多数学。更像是对集合的操作。
将 81 头奶牛分成 9 批,尺寸逐渐增大。
[ 1, 2, 3, 4, 5, 6, 7, 8, 9]
[10, 11, 12, 13, 14, 15, 16, 17, 18]
[19, 20, 21, 22, 23, 24, 25, 26, 27]
[28, 29, 30, 31, 32, 33, 34, 35, 36]
[37, 38, 39, 40, 41, 42, 43, 44, 45]
[46, 47, 48, 49, 50, 51, 52, 53, 54]
[55, 56, 57, 58, 59, 60, 61, 62, 63]
[64, 65, 66, 67, 68, 69, 70, 71, 72]
[73, 74, 75, 76, 77, 78, 79, 80, 81]
将每批内容比前一批左移一位。
[ 1, 2, 3, 4, 5, 6, 7, 8, 9]
[11, 12, 13, 14, 15, 16, 17, 18, 10]
[21, 22, 23, 24, 25, 26, 27, 19, 20]
[31, 32, 33, 34, 35, 36, 28, 29, 30]
[41, 42, 43, 44, 45, 37, 38, 39, 40]
[51, 52, 53, 54, 46, 47, 48, 49, 50]
[61, 62, 63, 55, 56, 57, 58, 59, 60]
[71, 72, 64, 65, 66, 67, 68, 69, 70]
[81, 73, 74, 75, 76, 77, 78, 79, 80]
每个儿子选择一列并拿走所有的牛。
son #1 gets [ 1, 11, 21, 31, 41, 51, 61, 71, 81], for a total of 369.
son #2 gets [ 2, 12, 22, 32, 42, 52, 62, 72, 73], for a total of 369.
son #3 gets [ 3, 13, 23, 33, 43, 53, 63, 64, 74], for a total of 369.
son #4 gets [ 4, 14, 24, 34, 44, 54, 55, 65, 75], for a total of 369.
son #5 gets [ 5, 15, 25, 35, 45, 46, 56, 66, 76], for a total of 369.
son #6 gets [ 6, 16, 26, 36, 37, 47, 57, 67, 77], for a total of 369.
son #7 gets [ 7, 17, 27, 28, 38, 48, 58, 68, 78], for a total of 369.
son #8 gets [ 8, 18, 19, 29, 39, 49, 59, 69, 79], for a total of 369.
son #9 gets [ 9, 10, 20, 30, 40, 50, 60, 70, 80], for a total of 369.
这种方法似乎适用于任意数量的儿子,而不仅仅是 9 个。
关于困惑如何用 C 实现数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23153447/