![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-10 16:01 |
47,811 topics / 349,897 posts / today 0 new / 48,255 members |
| DOS批处理 & 脚本技术(批处理室) » Methods to distribute 10 apples among 5 people |
| Printable Version 2,590 / 14 |
| Floor1 jmz573515 | Posted 2007-01-20 23:54 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
### Distribute 10 apples among 5 people (each person gets at least one apple)
[ Last edited by jmz573515 on 2007-2-1 at 02:27 PM ] |
|
| Floor2 PPdos | Posted 2007-01-21 00:17 |
| 高级用户 Posts 268 Credits 783 | |
|
Each person gets at least one apple. Otherwise, there are distributions like 10 and 0, which would make the number more than 126.
|
|
| Floor3 jmz573515 | Posted 2007-01-21 00:21 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
Thanks to the reminder from user 2, there should be the condition that "each person gets at least one apple".
|
|
| Floor4 namejm | Posted 2007-01-21 03:07 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
I'm following a bat version:
Still add the thick lines, so as not to affect the appearance ![]() [ Last edited by namejm on 2007-1-20 at 02:50 PM ] |
|
| Floor5 ccwan | Posted 2007-01-21 03:15 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Hundred schools of thought contending is a very good learning method, appreciate the two of you~~
|
|
| Floor6 tao0610 | Posted 2007-01-21 03:36 |
| 高级用户 Posts 218 Credits 579 | |
|
It can be done recursively, but the efficiency will be very low.
|
|
| Floor7 PPdos | Posted 2007-01-21 14:37 |
| 高级用户 Posts 268 Credits 783 | |
|
I have to admit, the moderator's layout is so clear and well-structured that it's easy to understand at a glance. I feel ashamed.
But in terms of calculation speed, VBS is a bit better. Probably because of this line "if !num! equ 10" that makes the program match automatically. .. If you want to increase the speed and don't know if there are other methods? |
|
| Floor8 jmz573515 | Posted 2007-01-22 00:16 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
Just modify it so that the number of apples can be entered.
[ Last edited by jmz573515 on 2007-1-22 at 10:07 PM ] |
|
| Floor9 namejm | Posted 2007-01-22 00:38 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Then I also modified the batch script that can specify the number of apples. I tested with 15 apples, and the batch script was indeed very slow, and the layout would also have problems (although it can be dealt with, but the code would be more complicated and not very universal):
|
|
| Floor10 tghksj01 | Posted 2007-01-23 08:50 |
| 初级用户 Posts 8 Credits 23 | |
|
This is actually a problem of the division method.
Teacher namejm and the previous几位 teachers used the method of nested collision testing, which will extremely waste resources and have extremely low efficiency when the modulus is relatively large. A more direct method is to use the IF statement to control the division rule and directly give the result according to the rule. The following is a crude example: [ Last edited by tghksj01 on 2007-1-31 at 04:20 PM ] |
|
| Floor11 tghksj01 | Posted 2007-02-01 05:22 |
| 初级用户 Posts 8 Credits 23 | |
|
Long time no see. I optimized the code a bit. Give it a thumbs up. Passers - by, please evaluate.
---------------- Went to the city today to participate in the computer skills competition, but the ranking was fixed again....郁闷... |
|
| Floor12 huzixuan | Posted 2007-02-01 07:26 |
| 高级用户 Posts 219 Credits 537 From 芜湖 | |
|
Make sure to see clearly!
|
|
| Floor13 anqing | Posted 2007-02-01 09:51 |
| 高级用户 Posts 413 Credits 859 | |
|
Although I can't understand it all, I admire it
|
|
| Floor14 gl315 | Posted 2007-02-02 01:46 |
| 新手上路 Posts 5 Credits 10 | |
|
I really envy, when will I be able to reach this level?
|
|
| Floor15 qjbm | Posted 2007-02-03 02:54 |
| 初级用户 Posts 44 Credits 125 | |
|
VBS indeed has inherent advantages... This is fully reflected in the code competition in this post.
The same "exhaustive collision test algorithm" VBS's: is much faster than the batch processing's: to an astonishing degree.... Does VBS automatically optimize the algorithm during execution? Its speed is almost comparable to the "segmentation method rule control" algorithm on floor 10. The "function" on floor 10 is already the ultimate algorithm.. but the speed is comparable to the exhaustive method of VBS code... It seems that batch processing is okay for saving some effort, but it's a bit incompetent when it comes to complex calculations.... |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |