穷举

  将所有可能性全部全部走一遍,使用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. bs4_2

     QQ:231469242 欢迎交流 Parsing HTML with the BeautifulSoup Module Beautiful Soup是用于提取HTML网页信息的模板,Beautif ...

  2. GLSL Interface Block参考

    http://www.opengl.org/wiki/Interface_Block_(GLSL) http://stackoverflow.com/questions/9916103/opengl- ...

  3. Python 开发与测试 Webservice(SOAP)

    WebService是一种跨编程语言和跨操作系统平台的远程调用技术. 理解WebService 1.从表面上看,WebService就是一个应用程序向外界暴露出一个能通过Web进行调用的API,也就是 ...

  4. jQuery简单实现iframe的高度根据页面内容自适应的方法

    同域下: //注意:下面的代码是放在和iframe同一个页面中调用 $("#myiframe").load(function () { var myiframeH = $(this ...

  5. HBase命令(二) -- 表操作

    创建表 hbase shell> create 'mytable','col1','col2' //建表语句 create '表名','列簇名','列簇名','列簇名' hbase shell& ...

  6. Java并发编程核心方法与框架-ScheduledExecutorService的使用

    类SchedukedExecutorService的主要作用是可以将定时任务与线程池功能结合. 使用Callable延迟运行(有返回值) public class MyCallableA implem ...

  7. CSS3导航效果

    来自codepen http://codepen.io/mouradhamoud/pen/RRvVZp <!DOCTYPE html> <html> <head> ...

  8. Sql Server作业

    参考资料: http://jingyan.baidu.com/article/49ad8bce7287315834d8fab4.html

  9. fedora23忘记root密码怎么办??

    fedora23使用的是uefi, 不是 传统的grub 所以在编辑grub的时候, 跟以前的版本略有不同 最最重要的是: 在编辑启动条目的时候, 那个 linuxefi ... vmlinuz... ...

  10. Java字节流:FilterInputStream FilterOutputStream

    ----------------------------------------------------------------------------------- FilterInputStrea ...