⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 列举法.htm

📁 枚举( enumerate)法是基于计算机运算速度快这一特性的一种使用非常普遍的思维方法。它是根据问题中的条件将可能的情况一一列举出来分析求解的方法。
💻 HTM
📖 第 1 页 / 共 2 页
字号:
              width=150></TD></TR></TBODY></TABLE></TD>
          <TD width=40></TD>
          <TD width=608>
            <TABLE cellSpacing=0 cellPadding=0 width=587>
              <TBODY>
              <TR>
                <TD width=585 colSpan=2>
                  <P align=right>&nbsp;</P></TD></TR>
              <TR>
                <TD width=181>
                  <P><IMG height=20 src="列举法.files/s2.gif" width=20 
                  align=absMiddle border=0> <B>列举法</B></P></TD>
                <TD width=402>
                  <P align=right><A 
                  href="http://www.muduhs.com/~yanxm/index1.htm">Index</A>&nbsp;&gt; 
                  <A href="http://www.muduhs.com/~yanxm/pds.htm">Alogri+Data 
                  str</A> &gt; <A 
                  href="http://www.muduhs.com/~yanxm/pds00.htm">常用算法</A> &gt; 
                  列举法</P></TD></TR>
              <TR>
                <TD width=585 background=列举法.files/bg.gif colSpan=2 
                height=1></TD></TR>
              <TR>
                <TD width=585 colSpan=2>
                  <P><BR>列举(枚举)法&nbsp;<BR><BR>枚举( 
                  enumerate)法是基于计算机运算速度快这一特性的一种使用非常普遍的思维方法。它是根据问题中的条件将可能的情况一一列举出来分析求解的方法。但有时一一列举出的情况数目很大,如果超过了我们所能忍受的范围则需要考虑如何去排除不合理的情况,尽可能减少列举的问题可能解的数目。&nbsp;<BR><BR>例:求一元三次方程的解。&nbsp;<BR><BR>有形如: 
                  ax3+bx2+cx+d=0一元三次方程。给出该方程中各项的系数 (a, b, c, d 均为实数 
                  ),并约定该方程存在三个不同实根 (根的范围在 -100至 100之间 ),且根与根之差的绝对值 
                  &gt;=1。要求由小到大依次在同一行上输出这三个实根。&nbsp;<BR><BR>这道题的解法很多,最为简洁的方法就是直接枚举可能的实根解。&nbsp;<BR><BR>&nbsp; 
                  var a,b,c,d:real;<BR>&nbsp; i:integer;&nbsp;<BR>function 
                  f(x:real):real;&nbsp;<BR>begin&nbsp;<BR>&nbsp; 
                  f:=a*x*x*x+b*x*x+c*x+d&nbsp;<BR>end;&nbsp;<BR>begin&nbsp;<BR>&nbsp; 
                  readln(a,b,c,d);&nbsp;<BR>&nbsp; for i:=-10000 to 10000 do 
                     {枚举方程所有可能的解}&nbsp;<BR>&nbsp;&nbsp; if 
                  abs(f(i/100))&lt;1e-4&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; then 
                  write(i/100:2:2,' 
                  ');&nbsp;<BR>end.<BR><BR>猴子选大王<BR>题目:有M个猴子围成一圈,每个有一个编号,编号从1到M。打算从中选出一个大王。经过协商,决定选大王的规则如下:从第一个开始,每隔N个,数到的猴子出圈,最后剩下来的就是大王。<BR>要求:从键盘输入M,N,编程计算哪一个编号的猴子成为大王。<BR><BR>program 
                  tt;<BR>&nbsp;const n1=100;<BR>&nbsp;var a:array [1..n1] of 
                  integer;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
                  m,n,i,j,k:integer;<BR>begin<BR>&nbsp;write('input 
                  m,n:');<BR>&nbsp;readln(m,n);<BR>&nbsp;for i:=1 to m 
                  do&nbsp;<BR>&nbsp;a[i]:=i;<BR>&nbsp;i:=1;<BR>&nbsp;k:=0;<BR>&nbsp;while 
                  i&lt;m do<BR>&nbsp;&nbsp; begin<BR>&nbsp;&nbsp;&nbsp; 
                  j:=0;<BR>&nbsp;&nbsp;&nbsp; while j&lt;=n 
                  do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  j:=j+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  k:=k+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if k&gt;m 
                  then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  k:=1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  while a[k]=0 
                  do&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  k:=k+1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  end;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                  end;<BR>&nbsp;&nbsp;&nbsp; a[k]:=0;<BR>&nbsp;&nbsp;&nbsp; 
                  i:=i+1;<BR>&nbsp;&nbsp; end;<BR>&nbsp;&nbsp; 
                  i:=1;<BR>&nbsp;&nbsp; while a[i]=0 do i:=i+1;<BR>&nbsp;&nbsp; 
                  writeln('The king is 
                  ',i);<BR>end.<BR><BR>变形猴子选大王<BR>题目:有M个人围成一圈,每人有一个编号,从编号为1的人开始,每隔N个出圈,按出圈次序排成一列,其编号刚好按顺序从1到M。<BR>要求:从键盘输入M,N,编程计算并输出这M个人原来在圈中的位置。<BR><BR>求数串的原始排列<BR>题目:前N个自然数排成一串: 
                  X1,X2,X3.....Xn,先取出x1,将x2,x3移到数串尾,再取出x4,将x4,x6移到数串尾,....... 
                  类推直至取完.<BR>取出的序列恰好是:1,2,3......n.要求输入N,求原来的数串的排列方式.<BR><BR>var 
                  a:array[1..1000] of 
                  word;<BR>n,i,j,dep:word;<BR>begin<BR>write('N(1-1000)=');<BR>readln(n);<BR>if 
                  (n=0) or (n&gt;1000) then begin<BR>writeln('Input 
                  error.');&nbsp;<BR>readln;&nbsp;<BR>halt;&nbsp;<BR>end;<BR>fillchar(a,sizeof(a),0);&nbsp;<BR>a[1]:=1;&nbsp;<BR>dep:=1;<BR>for 
                  i:=2 to n do begin<BR>j:=3;&nbsp;<BR>while (j&gt;0) do 
                  begin<BR>dep:=dep mod n+1;<BR>if a[dep]=0 then 
                  dec(j);<BR>end;<BR>a[dep]:=i;<BR>end;<BR>for i:=1 to n do 
                  write(a[i]:5);<BR>writeln;&nbsp;<BR>readln;<BR>end.<BR><BR>狐狸捉兔子<BR>问题:围绕着山顶有10个洞,狐狸要吃兔子,兔子说:“可以,但必须找到我,?我就藏身于这十个洞中,你从10号洞出发,先到1号洞找,第二次隔1个洞找,第三次隔2个洞找,以后如此类推,次数不限。”但狐狸从早到晚进进出出了1000次,仍没有找到兔子。问兔子究竟藏在哪个洞里?<BR><BR>【答案】2,4,7,9<BR><BR>【参考程序1】<BR><BR>const 
                  holenumber=10;<BR>&nbsp;var hole:array[0..holenumber] of 
                  0..1;<BR>&nbsp;step,i,number:longint;<BR>&nbsp;begin for i:=0 
                  to 9 do hole[i]:=0;<BR>&nbsp;number:=0;<BR>&nbsp;for step:=1 
                  to 1000 do<BR>&nbsp;begin number:=number+step; 
                  {循环地数}<BR>&nbsp;i:=number mod holenumber; 
                  {第几个洞}<BR>&nbsp;hole[i]:=1;<BR>&nbsp;end;<BR>&nbsp;for i:=0 to 
                  holenumber-1 do<BR>&nbsp;if hole[i]=0<BR>&nbsp;then 
                  write(i:3);<BR>&nbsp;readln;<BR>&nbsp;end.<BR>【参考程序2】<BR><BR>const 
                  m=10; {洞数}<BR>&nbsp;var 
                  l,f,t:integer;<BR>&nbsp;a:array[1..m+1] of 
                  0..1;<BR>&nbsp;begin<BR>&nbsp;for t:=1 to m 
                  do<BR>&nbsp;a[t]:=0;<BR>&nbsp;f:=0;<BR>&nbsp;t:=0;<BR>&nbsp;l:=0;<BR>&nbsp;repeat<BR>&nbsp;l:=l+1; 
                  {隔几个洞}<BR>&nbsp;t:=t+l; {第几个洞}<BR>&nbsp;if t&gt;m+1 then t:=t 
                  mod m;<BR>&nbsp;if t=0 then 
                  t:=10;{循环地找}<BR>&nbsp;a[t]:=1;{该洞已进过}<BR>&nbsp;f:=f+1; 
                  {进洞的次数}<BR>&nbsp;until f=1000;<BR>&nbsp;for t:=1 to 10 
                  do<BR>&nbsp;if a[t]=0<BR>&nbsp;then write(t,' 
                  ');<BR>&nbsp;readln<BR>&nbsp;end.&nbsp;<BR><BR></P></TD></TR></TBODY></TABLE></TD>
          <TD width=152>&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD vAlign=bottom height=81>  
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR bgColor=#cccccc>
          <TD width=800 height=1><IMG height=1 width=800></TD>
          <TD width=459 height=1></TD></TR>
        <TR vAlign=top>
          <TD width=800>
            <TABLE cellSpacing=0 cellPadding=0 width=800>
              <TBODY>
              <TR>
                <TD width=210 height=10></TD>
                <TD width=590 colSpan=2 height=10></TD></TR>
              <TR>
                <TD width=210 height=14>
                  <P align=center><A onfocus=this.blur() 
                  href="http://www.muduhs.com/" target=_blank><FONT face=Verdana 
                  color=#999999 size=1>GO Muduhs WebSite!</FONT></A> </P></TD>
                <TD width=536 height=14>
                  <P><FONT face=Verdana size=1>Copyright &#9426; MuDu - Internet 
                  HighSchool. Some right reserved.</FONT></P></TD>
                <TD width=54 height=14>
                  <P align=right><A onfocus=this.blur() 
                  href="http://www.muduhs.com/~yanxm/pds02.htm#"><FONT 
                  face=Verdana size=1><B>-TOP</B></FONT></A> </P></TD></TR>
              <TR>
                <TD width=210 height=10></TD>
                <TD width=590 colSpan=2 height=10></TD></TR></TBODY></TABLE></TD>
          <TD width=459></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><MAP 
name=ImageMap1><AREA shape=RECT coords=81,1,161,33 
  href="http://www.muduhs.com/~yanxm/pds.htm"><AREA shape=RECT 
  coords=161,1,240,33 href="http://www.muduhs.com/~yanxm/contest.htm"><AREA 
  shape=RECT coords=240,1,320,34 
  href="http://www.muduhs.com/~yanxm/circle.htm"><AREA shape=RECT 
  coords=319,1,401,35 href="http://www.muduhs.com/~yanxm/gellery.htm"><AREA 
  shape=RECT coords=401,2,479,35 
  href="http://www.muduhs.com/~yanxm/board.htm"><AREA shape=RECT 
  coords=1,1,82,33 
href="http://www.muduhs.com/~yanxm/about.htm"></MAP></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -