穷举

  将所有可能性全部全部走一遍,使用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循环的更多相关文章

  1. 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 ...

  2. 2016年12月10日 星期六 --出埃及记 Exodus 21:5

    2016年12月10日 星期六 --出埃及记 Exodus 21:5 "But if the servant declares, `I love my master and my wife ...

  3. 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 ...

  4. 2016年11月10日 星期四 --出埃及记 Exodus 20:1

    2016年11月10日 星期四 --出埃及记 Exodus 20:1 And God spoke all these words: 神吩咐这一切的话说,

  5. 2016年10月31日 星期一 --出埃及记 Exodus 19:16

    2016年10月31日 星期一 --出埃及记 Exodus 19:16 On the morning of the third day there was thunder and lightning, ...

  6. 2016年10月30日 星期日 --出埃及记 Exodus 19:15

    2016年10月30日 星期日 --出埃及记 Exodus 19:15 Then he said to the people, "Prepare yourselves for the thi ...

  7. 2016年10月29日 星期六 --出埃及记 Exodus 19:14

    2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...

  8. 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 ...

  9. 2016年10月27日 星期四 --出埃及记 Exodus 19:12

    2016年10月27日 星期四 --出埃及记 Exodus 19:12 Put limits for the people around the mountain and tell them, `Be ...

  10. 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 ...

随机推荐

  1. 阻塞式socket例子学习

    /************************************************************************* > File Name: Win_Serve ...

  2. crontab执行脚本中文乱码,手动执行没有问题

    crontab执行脚本中文乱码,手动执行没有问题 产生原因:       这是因为Unix/Linux下使用crontab时的运行环境已经不是用户环境了,因此原本用户下的一些环境变量的设置就失效了.例 ...

  3. MathML + MathJax在网页中插入公式

    http://www.mathjax.org/download/ http://www.w3.org/Math/Software/mathml_software_cat_editors.html ht ...

  4. css input checkbox和radio样式美化

    参考:https://segmentfault.com/a/1190000004553258 http://www.haorooms.com/post/css_mh_ck_radio 思路都一样的,先 ...

  5. App Store

    App store最新审核标准(2015.3)公布 http://www.cnii.com.cn/mobileinternet/2015-03/24/content_1550301.htm iOS提交 ...

  6. OC-点语法

    点语法的本质:方法调用 #import <Foundation/Foundation.h> #import "Person.h" int main(int argc, ...

  7. 缓存 HttpContext.Current.Cache和HttpRuntime.Cache的区别

    先看MSDN上的解释: HttpContext.Current.Cache:为当前 HTTP 请求获取Cache对象. HttpRuntime.Cache:获取当前应用程序的Cache.  我们再用. ...

  8. Markdown语言详解

    相信大家在github上面分享了不少的项目和Demo,每次创建新项目的时候,使用的都是默认的README.md文件,也不曾对这个文件有过什么了解.但是在看到别人写的项目的README.md里面竟然有图 ...

  9. jquery判断checkbox是否选中及改变checkbox状态

    转自:http://blog.csdn.net/limingchuan123456789/article/details/11499665 jquery判断checked的三种方法:.attr('ch ...

  10. django学习<一>:安装

    这两天打算摸索下和python相关的东西,然后正好小伙伴有个关于网站的任务,就怀着好奇的心态了解了下,然后就很自然地开始涉及django的问题. 首先就是django安装的问题,想不到第一步就出问题了 ...