- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
商人过河问题(Businessman crossing the river).doc
商人过河问题(Businessman crossing the river)
N k a servant businessman across the river, the boat up to m, on both sides of any one bank more than number of businessmen are businessmen and will die, ask how to arrange to make successful businessmen across the river, if not do not print out the whole process: it is recommended to start value =3, k=3, m=2
Thanks for the prawns
#include iostream.h
Void main ()
{
Int n, k m, n k m; / / if the requirements of the subject n=k, m=1
Int x, y, Z; //xy means every merchant and servant on board, and Z is a temporary variable
Int i = 0; / / the number of delivery
Do
{
Cout input merchant, number of servants and ship carrying capacity.:;
Cinnkm;
If (nk m1 ||) / sub topic request
Cout input does not meet the requirements of the subject, please re-enter. endl;
}while (nk m1 ||);
If (n = = k) / / critical state, the number of businessmen and the number of servants, that every time delivery.
X = y = m/2;
Else
{
Y = m / 2; / / the number of carrier servant
X = m - Y; / / the number of merchants set
}
While (n =0 K ||!! / / =0) as long as there are people to be shipped
{
I++;
Cout No. i second delivery. endl;
If (n x)
{
N-=x;
Cout this merchant x one. endl;
}
Else
{
Cout this merchant n one. endl;
N = 0; / / merchant shipping.
}
If (k y)
{
K -=y;
Cout deliver this servant y one. endl;
}
Else
{
Cout deliver this servant k one. endl;
K = 0;
}
Z = x;
X = y;
Y = Z; / / x y exchange
}
Return;
}
///////////////////////
#include stdio.h
#include string.h
#include conio.h
FILE *fp; / * set the file pointer, so that it can be used in other functions.
Struct a{
Long m, s;
Struct a *next;
}; / * the array type A: the records of all cases of a ship of the merchant and the number of servants, on behalf of the merchant number: M
S: the number of servants on behalf of.
Struct a *jj, head /*head; for the list of unit head pointer (various number of people on board the list).
Int n, total=0, js=0; /*total said the ship of the total.
Struct aim {
Long M1,
您可能关注的文档
- 变频器过电压故障原因分析及对策(Cause analysis and Countermeasures of inverter over voltage fault).doc
- 国外施肥机和植保机的发展现状和技术特点.doc
- SECCI ;N S ;NTOMAS Y SIGNOS - Apuntes y recursos ….doc
- 对超高分子量聚乙烯的开发与应用分析_论文.docx
- 数列与级数数列与级数a等差数列与等比数列数列若.doc
- 黄淮海地区玉米收获机.doc
- 小檗碱提取工艺的研究_论文.docx
- Mn掺杂纳米SnO_的气敏性能研究_梅军鹏.doc
- 如何做好玉米青贮.doc
- 平衡小车原理分析.doc
- -年级下科学答案.doc
- 国际贸易丶资源与环境中三种外部性相互作用的理论探讨与实证检验.doc
- ThinkPad预装Win的分区方法.docx
- 电气工程及其自动化发展趋势探讨.docx
- QJZ系列矿用隔爆兼本质安全型可逆真空电磁起动器.doc
- 项目一单片机最小系统设计(The smallest system design of project single chip microcomputer).doc
- 培训----高中数学中的向量及其应用.doc
- 化学工程专业优秀论文 基于丙烯酸盐型离聚物的pet成核结晶过程及熔融行为研究.doc
- 预拌混凝土配合比设计专题讨论.doc
- 反式脂肪酸(Trans fatty acids).doc
文档评论(0)