2016年10月10日--穷举、迭代、while循环
穷举
将所有可能性全部全部走一遍,使用IF筛选出满足的情况
练习:
1.单位给发了一张150元购物卡,
拿着到超市买三类洗化用品。
洗发水15元,香皂2元,牙刷5元。
求刚好花完150元,有多少种买法,
没种买法都是各买几样?

;
;
; x <= ; x++)
{
; y <= ; y++)
{
; z <= ; z++)
{
j++;
+ y * + z * == )
{
i++;
Console.WriteLine("方法{0},买洗发水【{1}】、牙刷【{2}】,香皂【{3}】", i, x, y, z);
}
}
}
}
Console.WriteLine("一共有{0}种买法方法", i);
Console.WriteLine("共走{0}遍", j);
答案
2.百鸡百钱:
公鸡2文钱一只,母鸡1文钱一只,小鸡半文钱一只,
总共只有100文钱,如何在凑够100只鸡的情况下刚好花完100文钱?

;
;
; x * <= ; x++)
{
; y <= ; y++)
{
; z * ; z++)
{
j++;
) + y + (z * && x + z + y == )
{
i++;
Console.WriteLine("方法{0},买公鸡【{1}】、母鸡【{2}】,小鸡【{3}】 一共【{4}】只", i, x, y, z, x + z + y);
}
}
}
}
Console.WriteLine("一共有{0}种买法方法", i);
Console.WriteLine("共走{0}遍", j);
答案
迭代
从初始情况按照规律不断求解中间情况,最终推导出结果。
练习:
1.折纸超过珠峰 8848

double zhi = 0.070;
;
for (; ; )
{
ci++;
zhi *= ;
Console.WriteLine(+"M");
)
{
break;
}
}
Console.WriteLine("共折{0}遍", ci);
答案
2.第一天1分钱,第二天2分钱,第三天4分钱,依次递增

;
;
; z <= ; z++)
{
)
{
qian = ;
}
else
{
qian *= ;
sum += qian;
}
Console.WriteLine();
}
Console.WriteLine();
答案
while循环
格式1:先判断,在做 while(表达式){}
格式2:先做,在判断 do{}while(表达式);
//for (int i = 1; i <= 5;i++ ){ }
//int i = 1;
//for (; i <= 5;i++ ){ }
//int i = 1;
//for (; i <= 5; ){ i++; }
//int i = 1;
//while(i <= 5){ i++; }
for 变 while
由上可知,for循环也可以变为 while循环;
2016年10月10日--穷举、迭代、while循环的更多相关文章
- 2016年12月15日 星期四 --出埃及记 Exodus 21:10
2016年12月15日 星期四 --出埃及记 Exodus 21:10 If he marries another woman, he must not deprive the first one o ...
- 2016年12月10日 星期六 --出埃及记 Exodus 21:5
2016年12月10日 星期六 --出埃及记 Exodus 21:5 "But if the servant declares, `I love my master and my wife ...
- 2016年11月19日 星期六 --出埃及记 Exodus 20:10
2016年11月19日 星期六 --出埃及记 Exodus 20:10 but the seventh day is a Sabbath to the LORD your God. On it you ...
- 2016年11月10日 星期四 --出埃及记 Exodus 20:1
2016年11月10日 星期四 --出埃及记 Exodus 20:1 And God spoke all these words: 神吩咐这一切的话说,
- 2016年10月31日 星期一 --出埃及记 Exodus 19:16
2016年10月31日 星期一 --出埃及记 Exodus 19:16 On the morning of the third day there was thunder and lightning, ...
- 2016年10月30日 星期日 --出埃及记 Exodus 19:15
2016年10月30日 星期日 --出埃及记 Exodus 19:15 Then he said to the people, "Prepare yourselves for the thi ...
- 2016年10月29日 星期六 --出埃及记 Exodus 19:14
2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...
- 2016年10月28日 星期五 --出埃及记 Exodus 19:13
2016年10月28日 星期五 --出埃及记 Exodus 19:13 He shall surely be stoned or shot with arrows; not a hand is to ...
- 2016年10月27日 星期四 --出埃及记 Exodus 19:12
2016年10月27日 星期四 --出埃及记 Exodus 19:12 Put limits for the people around the mountain and tell them, `Be ...
- 2016年10月26日 星期三 --出埃及记 Exodus 19:10-11
2016年10月26日 星期三 --出埃及记 Exodus 19:10-11 And the LORD said to Moses, "Go to the people and consec ...
随机推荐
- 20145212 《Java程序设计》第8周学习总结
20145212 <Java程序设计>第8周学习总结 教材学习内容总结 第十四章 NIO与NIO2 认识NIO NIO使用频道(Channel)来衔接数据节点,在处理数据时,NIO可以让你 ...
- python开发_++i,i += 1的区分
python开发_++i,i += 1的区分 在很多编程语言(C/C++,Java等)中我们都会碰到这样的语法: 1 int i = 0; 2 ++ i; // -- i; 这样的语法在上述编程语言中 ...
- -[UIKeyboardLayoutStar release]: message sent to deallocated instance
网上大家都说是因为替换了系统的objextAtIndex方法,但是为了减少应用崩溃的可能,是要进行Hook的,所以不想取消Hook. 解决办法,关掉键盘进入后台. - (void)applicatio ...
- Docker Dockerfile COPY vs ADD
http://blog.163.com/digoal@126/blog/static/163877040201410341236664/ 在Dockerfile中, 我们可以使用ADD和COPY拷 ...
- mysql和oracle的区别(功能性能、选择、使用它们时的sql等对比)
一.并发性 并发性是oltp数据库最重要的特性,但并发涉及到资源的获取.共享与锁定. mysql:mysql以表级锁为主,对资源锁定的粒度很大,如果一个session对一个表加锁时间过长,会让其他se ...
- 【转】asp.net mvc 页面跳转
1.使用传统的Response.Redirect例如string url = "/account/create";Response.Redirect(url); 1.Server. ...
- 【干货理解】理解javascript中实现MVC的原理
理解javascript中的MVC MVC模式是软件工程中一种软件架构模式,一般把软件模式分为三部分,模型(Model)+视图(View)+控制器(Controller); 模型:模型用于封装与应用程 ...
- PHP 线程安全与非线程安全版本的区别深入解析
Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍 ...
- document.all的详细解释(document.all基本上所有浏览器可用!)
从何而来从IE4开始IE的object model才增加了document.all对象,MSDN中也对 Object.all 有详细的说明,Object.all是个HTMLCollection,不是数 ...
- [译]angularjs directive design made easy
原文: http://seanhess.github.io/2013/10/14/angularjs-directive-design.html AngularJS directives很酷 Angu ...