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

📄 usaco 2_1_1 the castle 题解 usaco分析的翻译【原创翻译】_leokan的blog.mht

📁 美国USACO题库源程序
💻 MHT
📖 第 1 页 / 共 5 页
字号:
A=20
href=3D"http://hi.baidu.com/leokan/profile">=B8=F6=C8=CB=B5=B5=B0=B8</A> =
<SPAN>|</SPAN><A=20
href=3D"http://hi.baidu.com/leokan/friends">=BA=C3=D3=D1</A> =
<SPAN>|</SPAN><A=20
href=3D"http://hi.baidu.com/leokan/modify/spbasic/0">=C9=E8=D6=C3</A> =
</DIV></DIV>
<DIV class=3Dstage>
<DIV class=3Dstagepad>
<DIV style=3D"WIDTH: 100%">
<TABLE class=3Dmodth cellSpacing=3D0 cellPadding=3D0 width=3D"100%" =
border=3D0>
  <TBODY>
  <TR>
    <TD class=3Dmodtl width=3D7>&nbsp;</TD>
    <TD class=3Dmodtc noWrap>
      <DIV class=3Dmodhead><SPAN =
class=3Dmodtit>=B2=E9=BF=B4=CE=C4=D5=C2</SPAN></DIV></TD>
    <TD class=3Dmodtc noWrap align=3Dright>
      <DIV class=3Dmodopt><A class=3Dmodact=20
      href=3D"http://hi.baidu.com/leokan/creat/blog/"><IMG=20
      src=3D"http://img.baidu.com/hi/img/ico_postnew.gif" =
align=3DabsMiddle=20
      border=3D0>=D0=B4=D0=C2=CE=C4=D5=C2</A></DIV></TD>
    <TD class=3Dmodtr width=3D7>&nbsp;</TD></TR></TBODY></TABLE>
<DIV class=3Dmodbox id=3Dm_blog>
<DIV class=3Dtit>USACO 2.1.1 The Castle =CC=E2=BD=E2 =
USACO=B7=D6=CE=F6=B5=C4=B7=AD=D2=EB=A1=BE=D4=AD=B4=B4=B7=AD=D2=EB=A1=BF</=
DIV>
<DIV class=3Ddate>2008=C4=EA01=D4=C227=C8=D5 =D0=C7=C6=DA=C8=D5 =
21:13</DIV>
<TABLE style=3D"TABLE-LAYOUT: fixed">
  <TBODY>
  <TR>
    <TD>
      <DIV class=3Dcnt>
      <P><STRONG></STRONG></P>
      <H2>USACO 2.1.1 The Castle</H2>
      <DIV class=3Dt_msgfont>The Castle<BR>IOI'94 - Day 1 <BR>In a =
stroke of luck=20
      almost beyond imagination, Farmer John was sent a ticket to the =
Irish=20
      Sweepstakes (really a lottery) for his birthday. This ticket =
turned out to=20
      have only the winning number for the lottery! Farmer John won a =
fabulous=20
      castle in the Irish countryside. <BR><BR>Bragging rights being =
what they=20
      are in Wisconsin, Farmer John wished to tell his cows all about =
the=20
      castle. He wanted to know how many rooms it has and how big the =
largest=20
      room was. In fact, he wants to take out a single wall to make an =
even=20
      bigger room. <BR><BR>Your task is to help Farmer John know the =
exact room=20
      count and sizes. <BR><BR>The castle floorplan is divided into M =
(wide) by=20
      N (1 &lt;=3DM,N&lt;=3D50) square <SPAN class=3Dt_tag=20
      href=3D"tag.php?name=3Dmod">mod</SPAN>ules. Each such <SPAN =
class=3Dt_tag=20
      href=3D"tag.php?name=3Dmod">mod</SPAN>ule can have between zero =
and four=20
      walls. Castles always have walls on their "outer edges" to keep =
out the=20
      wind and rain. <BR><BR>Consider this annotated floorplan of a =
castle:=20
      <BR><BR>&nbsp;&nbsp;&nbsp; 1 2 3 4 5 6=20
      7<BR>#############################<BR>1 # | # | # | |=20
      #<BR>#####---#####---#---#####---# <BR>2 # # | # # # #=20
      #<BR>#---#####---#####---#####---#<BR>3 # | | # # # # #=20
      <BR>#---#########---#####---#---#<BR>4 # -&gt;# | | | | # #=20
      <BR>############################# <BR><BR>#&nbsp;&nbsp; =3D Wall=20
      &nbsp;&nbsp;&nbsp; -,|&nbsp;&nbsp; =3D No wall<BR>-&gt; =3D Points =
to the wall=20
      to remove to<BR>&nbsp;&nbsp;&nbsp; make the largest possible new=20
      room<BR><BR>By way of example, this castle sits on a 7 x 4 base. A =
"room"=20
      includes any set of connected "squares" in the floor plan. This =
floorplan=20
      contains five rooms (whose sizes are 9, 7, 3, 1, and 8 in no =
particular=20
      order). <BR><BR>Removing the wall marked by the arrow merges a =
pair of=20
      rooms to make the largest possible room that can be made by =
removing a=20
      single wall. <BR><BR>The castle always has at least two rooms and =
always=20
      has a wall that can be removed. <BR><BR>PROGRAM NAME: =
castle<BR>INPUT=20
      FORMAT<BR>The map is stored in the form of numbers, one number for =
each=20
      module, M numbers on each of N lines to describe the floorplan. =
The input=20
      order corresponds to the numbering in the example diagram above.=20
      <BR><BR>Each module number tells how many of the four walls exist =
and is=20
      the sum of up to four integers: <BR><BR>1: wall to the west <BR>2: =
wall to=20
      the north <BR>4: wall to the east <BR>8: wall to the south =
<BR>Inner walls=20
      are defined twice; a wall to the south in module 1,1 is also =
indicated as=20
      a wall to the north in module 2,1. Line 1:&nbsp;&nbsp; Two =
space-separated=20
      integers: M and N <BR>Line 2..:&nbsp;&nbsp; M x N integers, =
several per=20
      line.&nbsp;&nbsp;<BR><BR><BR>SAMPLE INPUT (file castle.in) <BR>7 =
4<BR>11 6=20
      11 6 3 10 6<BR>7 9 6 13 5 15 5<BR>1 10 12 7 13 7 5<BR>13 11 10 8 =
10 12=20
      13<BR><BR>OUTPUT FORMAT<BR>The output contains several lines: Line =

      1:&nbsp;&nbsp; The number of rooms the castle =
has.&nbsp;&nbsp;<BR>Line=20
      2:&nbsp;&nbsp; The size of the largest room <BR>Line =
3:&nbsp;&nbsp; The=20
      size of the largest room creatable by removing one=20
      wall&nbsp;&nbsp;<BR>Line 4:&nbsp;&nbsp; The single wall to remove =
to make=20
      the largest room possible <BR><BR><BR>Choose the optimal wall to =
remove=20
      from the set of optimal walls by choosing the wall farthest to the =
west=20
      (and then, if still tied, farthest to the south). Name that wall =
by naming=20
      the module that borders it on either the west or south, along with =
a=20
      direction of N or E giving the location of the wall with respect =
to the=20
      module. <BR><BR>SAMPLE OUTPUT (file =
castle.out)<BR>5<BR>9<BR>16<BR>4 1=20
      E<BR><BR><BR><BR>The Castle <BR><BR>=B3=C7=B1=A4<BR><BR>IOI'94 - =
Day 1 <BR><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5=C4=C8=CE=CE=F1=CA=C7=B0=EF=D6=FA=C5=A9=C3=F1=D4=BC=BA=
=B2=C8=A5=C1=CB=BD=E2=D5=FD=C8=B7=B7=BF=BC=E4=CA=FD=C4=BF=BA=CD=B4=F3=D0=A1=
=A1=A3<BR>=B3=C7=B1=A4=B5=C4=C6=BD=C3=E6=CD=BC=B1=BB=B7=D6=CE=AA=20
      M(wide)*N(1=20
      =
&lt;=3DM,N&lt;=3D50)=B8=F6=D0=A1=D5=FD=B7=BD=D0=CE=A1=A3<BR>=C3=BF=B8=F6=D5=
=E2=D1=F9=B5=C4=D0=A1=D5=FD=B7=BD=D0=CE=D3=D00=B5=BD4=C3=E6=C7=BD=A1=A3<B=
R>=B3=C7=B1=A4=D4=DA=CB=FC=B5=C4=CD=E2=B2=BF=B1=DF=D4=B5=D7=DC=CA=C7=D3=D0=
=C7=BD=B1=DA=B5=C4=A3=AC=BA=C3=D5=DA=B5=B2=B7=E7=D3=EA=A1=A3<BR><BR>=BF=BC=
=C2=C7=D5=E2=D7=A2=BD=E2=C1=CB=D2=BB=B8=F6=B3=C7=B1=A4=B5=C4=C6=BD=C3=E6=CD=
=BC=A3=BA<BR>&nbsp;&nbsp;&nbsp;=20
      1 2 3 4 5 6 7<BR>#############################<BR>1 # | # | # | |=20
      #<BR>#####---#####---#---#####---# <BR>2 # # | # # # #=20
      #<BR>#---#####---#####---#####---#<BR>3 # | | # # # # #=20
      <BR>#---#########---#####---#---#<BR>4 # -&gt;# | | | | # #=20
      <BR>############################# <BR><BR># =3D=C7=BD=B1=DA -, | =
=3D =C3=BB=D3=D0=C7=BD=B1=DA<BR>-&gt;=20
      =
=3D=D2=C6=B3=FD=D5=E2=C3=E6=C7=BD=C4=DC=CA=B9=B5=C3=B5=BD=B5=C4=D0=C2=B7=BF=
=BC=E4=D7=EE=B4=F3<BR><BR><BR>=C0=FD=D7=D3=B5=C4=B3=C7=B1=A4=B5=C4=B4=F3=D0=
=A1=CA=C77 x 4=A1=A3<BR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2=D4=C1=CB=A3=AC=D5=E2=D1=F9=BC=F2=B1=E3=C1=CB=BA=DC=B6=E0=A3=
=AC80=D0=D0ac=A1=A3</STRONG></P>
      <P><STRONG>=BD=E8=D3=C3usaco=B5=C4=B7=D6=CE=F6=A3=BA</STRONG></P>
      <P><STRONG><FONT =
color=3D#ff0000>=CE=D2=C3=C7=D3=C3=D2=BB=B8=F6=C6=D3=CB=D8=B5=C4=B5=DD=B9=
=E9floodfill=20
      =
=C0=B4=CC=EE=B3=E4=C3=BF=D2=BB=B8=F6=B3=C7=B1=A4=C0=EF=B5=C4=B7=BF=BC=E4=A3=
=AC=C8=BB=BA=F3=B2=E9=BF=B4=C3=BF=B6=D4=CE=D2=C3=C7=BF=C9=D2=D4=CD=A8=B9=FD=
=C7=C3=CB=E9=C7=BD=B1=DA=B6=F8=C1=AA=CD=A8=B5=C4<STRONG>=B7=BF=BC=E4=A3=AC=
=D3=C9=D3=DA=CE=D2=C3=C7=BD=AB=D2=AA=D3=C3=D7=EE=CE=F7=B5=C4=BA=CD=D7=EE=C4=
=CF=B5=C4=B7=BD=B8=F1=A3=AC=CB=F9=D2=D4=CE=D2=C3=C7=D6=BB=D0=E8=D2=AA=BF=BC=
=C2=C7=C7=C3=CB=E9=B1=B3=C3=E6=B5=C4=C7=BD=BA=CD=B6=AB=C3=E6=B5=C4=A1=A3<=
/STRONG></FONT></STRONG></P>
      <P><STRONG>{<BR>TASK:castle<BR>LANG:PASCAL<BR>}<BR>program=20
      castle;<BR>const<BR>&nbsp;&nbsp;&nbsp; shl2:array[1..4]of=20
      integer=3D(1,2,4,8);<BR>&nbsp;&nbsp;&nbsp; index:array[2..3,1..2] =
of=20
      integer=3D((-1,0),(0,1));<BR>var<BR>&nbsp;&nbsp;&nbsp;=20
      map:array[1..50,1..50,1..4] of boolean;<BR>&nbsp;&nbsp;&nbsp;=20
      fill:array[1..50,1..50] of integer;<BR>&nbsp;&nbsp;&nbsp;=20
      area:array[1..2500] of integer;<BR>&nbsp;&nbsp;&nbsp;=20
      n,m:integer;<BR>procedure init;<BR>var<BR>&nbsp;&nbsp;&nbsp;=20
      i,j,k,x:integer;<BR>begin<BR>&nbsp;&nbsp;&nbsp;=20
      assign(input,'castle.in');reset(input);<BR>&nbsp;&nbsp;&nbsp;=20
      readln(m,n);<BR>&nbsp;&nbsp;&nbsp;=20
      fillchar(map,sizeof(map),true);<BR>&nbsp;&nbsp;&nbsp; for i:=3D1 =
to n=20
      do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
      for j:=3D1 to m=20
      =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
read(x);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      for k:=3D1 to 4=20
      =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      if x and shl2[k]&lt;&gt;0=20
      =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
map[i,j,k]:=3Dfalse;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
end;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
      readln;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      end;<BR>&nbsp;&nbsp;&nbsp;=20
      fillchar(fill,sizeof(fill),0);<BR>&nbsp;&nbsp;&nbsp;=20
      fillchar(area,sizeof(area),0);<BR>&nbsp;&nbsp;&nbsp;=20
      close(input);<BR>end;<BR>procedure=20
      floodfill(x,y,c:integer);<BR>begin<BR>&nbsp;&nbsp;&nbsp; if =
fill[x,y]=3D0=20
      then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
      =
fill[x,y]:=3Dc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;=20
      =
inc(area[c]);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
      if map[x,y,1] then=20
      =
floodfill(x,y-1,c);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
      if map[x,y,2] then=20
      =
floodfill(x-1,y,c);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
      if map[x,y,3] then=20
      =
floodfill(x,y+1,c);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
      if map[x,y,4] then=20
      floodfill(x+1,y,c);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      end;<BR>end;<BR>procedure work;<BR>var<BR>&nbsp;&nbsp;&nbsp;=20
      i,j,colour,maxarea,k,x,y,w:integer;<BR>begin<BR>&nbsp;&nbsp;&nbsp; =

      assign(output,'castle.out');rewrite(output);<BR>&nbsp;&nbsp;&nbsp; =

      colour:=3D0;<BR>&nbsp;&nbsp;&nbsp; =
maxarea:=3D0;<BR>&nbsp;&nbsp;&nbsp; for=20
      i:=3D1 to n do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for =
j:=3D1 to m=20
      =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

      if fill[i,j]=3D0=20
      =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
inc(colour);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
floodfill(i,j,colour);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      if area[colour]&gt;maxarea=20
      =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
      =
maxarea:=3Darea[colour];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      end;<BR>&nbsp;&nbsp;&nbsp; writeln(colour);<BR>&nbsp;&nbsp;&nbsp;=20
      writeln(maxarea);<BR>&nbsp;&nbsp;&nbsp; =
maxarea:=3D0;<BR>&nbsp;&nbsp;&nbsp;=20
      for j:=3D1 to m do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
for i:=3Dn=20
      downto 1=20
      =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

      for k:=3D2 to 3=20
      =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;=20
      if not map[i,j,k]=20
      =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
      if=20
      =
(i+index[k,1]&gt;0)and(j+index[k,2]&lt;=3Dm)and(fill[i,j]&lt;&gt;fill[i+i=
ndex[k,1],j+index[k,2]])and=20
      (area[fill[i,j]]+area[fill[i+index[k,1],j+index[k,2]]]&gt;maxarea) =

      =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
begin<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
maxarea:=3Darea[fill[i,j]]+area[fill[i+index[k,1],j+index[k,2]]];<BR>&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
x:=3Di;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =
y:=3Dj;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
      =

⌨️ 快捷键说明

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