资源预览内容
第1页 / 共12页
第2页 / 共12页
第3页 / 共12页
第4页 / 共12页
第5页 / 共12页
第6页 / 共12页
第7页 / 共12页
第8页 / 共12页
第9页 / 共12页
第10页 / 共12页
亲,该文档总共12页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
算法分析大型实验报告 编号编号标题标题算法算法 题目一题目一1005Jugs模拟模拟 题目二题目二1007Do the Untwist字符串字符串 班班级级: 姓姓名名: 学学号号: 指导老师指导老师: 20112011 年年 8 8 月月 ZJUT-1005 Jugs1 Special Judge Time limit: 1 SecondsMemory limit: 32768K In the movie “Die Hard 3“, Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This problem generalizes that puzzle. You have two jugs, A and B, and an infinite supply of water. There are three types of actions that you can use: (1) you can fill a jug, (2) you can empty a jug, and (3) you can pour from one jug to the other. Pouring from one jug to the other stops when the first jug is empty or the second jug is full, whichever comes first. For example, if A has 5 gallons and B has 6 gallons and a capacity of 8, then pouring from A to B leaves B full and 3 gallons in A. A problem is given by a triple (Ca,Cb,N), where Ca and Cb are the capacities of the jugs A and B, respectively, and N is the goal. A solution is a sequence of steps that leaves exactly N gallons in jug B. The possible steps are fill A fill B empty A empty B pour A B pour B A success where “pour A B“ means “pour the contents of jug A into jug B“, and “success“ means that the goal has been accomplished. You may assume that the input you are given does have a solution. Input Input to your program consists of a series of input lines each defining one puzzle. Input for each puzzle is a single line of three positive integers: Ca, Cb, and N. Ca and Cb are the capacities of jugs A and B, and N is the goal. You can assume 0 using namespace std; int main() int ca,cb,n; while (cincacbn) int bnow; int b = 0; while (b != n) /只要 b 水壶不溢出,就让 a 水壶灌个够 for (int i=0; i #include using namespace std; int main() int k;/key char a80;/原始密文 char c80;/解密后的明文 int b100;/ciphercode while(cink int n = strlen(a); /根据原始密文,计算 ciphercode for(int i=0; i=a struct Fat int bean;/存放该库房中 JavaBean int food;/存放换取该库房中的 JavaBean 所需要的猫食代价 double good;/用猫食换取 JavaBean 时的性价比 ; int main() /ifstream cin(“ch05-04.in“); int m, n; Fat iMouse1001; while(cinmn i iMousei.beaniMousei.food; iMousei.good = double (iMousei.bean) / iMousei.food; /按性价比进行降序排序(冒泡排序) for(int i = 0; i = iMousei.food) sum += iMousei.bean; m -= iMousei.food; else /所剩猫食不多换取一个库房的 JavaBean,按比例换取 JavaBean sum += iMousei.bean * double(m) / iMousei.food; break; cout.precision(3); coutfixedsumendl; return 0; 附录:设计说明书格式附录:设计说明书格式(请删除请删除) 全部为 5 号字,单倍行距! 中文:宋体; 英文:Times New Roman; 首行缩进:2 字符
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号