ベルク・カッツェ |
往復20×20=400通り。
スタート地点から上に一歩行き、帰りもそこを通るのが10×10で100通り、一歩右の場合も100通りで合わせて200通り。 どちらでも同じところを通らず、右1上1を行きにも帰りにも通るのが72通り。 こうやって調べていって、どこかで交わるものが全部で200+72+36+4+24+24=360通り。 よって求める答えは200-360=40通りになりました。 |
9月10日(木) 0:21:47
49519 |
ベルク・カッツェ |
ところで、過去問で似たような問題があったような気がするのですが、気のせいでしょうか。
年のせいか記憶が曖昧です。 |
9月10日(木) 0:25:09
49520 |
げほげほ |
ずばり、この330問目の類題ですね!
http://www.sansu.org/used-html/index330.html |
プププランド
9月10日(木) 0:27:40
HomePage:正体不明(あんのうん) 49521 |
algebra |
入り口から右に進み、最後は上に進んでカレー店Mへ入るのは6通り
この6通りについて、帰りの進み方を考えて、6+5+2+1+3×2=20(通り) よって、求める道順は、20×2=40(通り) |
9月10日(木) 0:32:14
49522 |
ベルク・カッツェ |
#49521
ありがとうございます。 私が参加する前なのでやったことはないはずですが、見覚えがありますね。 最近にも類題があってそのときに見たのかな。 #49522 どう考えてもそちらのほうが簡単ですね。無駄に手間をかけてしまいました。 |
9月10日(木) 0:51:28
49523 |
Mr.ダンディ |
algebraさんの #49522
と同様にしました。 (このような場合分けせずに楽に求める方法はあるのだろうか?) |
9月10日(木) 0:52:45
49524 |
今年から高齢者 |
algebraさん#49522のように、最初に上に進む、6パターンを数えあげ。
6+5+3+3+2+1=20。最初に横に進む場合を含めて、20*2=40。 第330問のマサルさんの書き込みが理解できなくて、今回も根気よく....。 |
9月10日(木) 1:11:24
49525 |
消しゴムパトロール |
私もalgebraさんの #49522 と同じです
かけ算して重複を引くなどでできなくはないと思いますが、 どう考えてもこれが最速でしょう |
9月10日(木) 1:26:30
49526 |
ベルク・カッツェ |
#49525
それです、思い出しました。 今回の場合だと、6×6-4×4=20、20×2=40で簡単に出せましたね。 すっかり忘れていたおかげで、類題でもう一度楽しめました。 |
9月10日(木) 1:29:17
49527 |
今年から高齢者 |
algebraさん#49522のように、最初に上に進む、6パターンを数えあげ。
6+5+3+3+2+1=20。最初に横に進む場合を含めて、20*2=40。 第330問のマサルさんの書き込みが理解できなくて、今回も根気よく....。 |
9月10日(木) 1:38:03
49528 |
今年から高齢者 |
#49527ベルク・カッツェ様
6は判るのですが、4はどのような考えで出てくるのでしょうか? No330もそれで困ったのですが... 管理者にお願い!49525と49528がダブりました。変な操作をした覚えはないのですが...できましたなら49528を削除下さい。 できれば |
9月10日(木) 1:52:06
49529 |
ベルク・カッツェ |
330回と同じようにABXYを設定します。
行きのルートをA-Y、帰りのルートをX−Bとすると、それぞれ4c1=4通りなので往復で4×4=16通りになり、必ずどこかで同じ点を通ります。 この16通りのいずれも、最も左下の共有点でその右上をそっくり入れ替えると、A-NルートとX-Yルートが共有点を持つ場合と完全に一致します。 こんな説明でいかがでしょうか。 |
9月10日(木) 2:06:32
49530 |
げほげほ |
一般に「高さhマス、幅wマス」のケースを解く方法を2つほど書いてみます。
以下、入口の座標を(0,0) カレー店の座標を(w,h)とします 解法1:過去問(第330問)の解法を踏襲 題意を満たすような経路は(0,1),(w-1,h),(w,h-1),(1,0)の4点を この順もしくはこの逆順にちょうど1回ずつ通ることになります。 逆順についてはあとで2倍すればいいので、この順の最短経路を考えましょう。 題意を満たさないものも含めて全て数え上げると ((h+w-2)C(w-1))^2通り ですね。 あとはこれから「行きと帰りで交わってしまうケース」を引けばいいわけですが それは「最初の交点で行きと帰りの経路を取り替える」という操作によって 「(0,1)から(w,h-1)への経路数 × (1,0)から(w-1,h)への経路数」と1:1に対応します。 よって (h+w-2)Cw × (h+w-2)Ch 通りと求めることができます。 つまり答えは ((h+w-2)C(w-1))^2 - ((h+w-2)Cw)*((h+w-2)Ch) を2倍すればよく とくに h=w=3 のケースだと ( (4C2)^2-(4C3)^2 )*2 = (36-16)*2 = 40 となるわけですね! 解法2:組み合わせ論の知識で殴る(笑) 今回の問題において、題意を満たす経路で囲まれる部分の図形は 「平行四辺形ポリオミノ」と呼ばれるものになります。(図でいうと、赤線と青線に囲まれた部分) 答えは結局のところ「3×3の平行四辺形ポリオミノの個数の2倍」ですね。 一般にh×wの平行四辺形ポリオミノの個数は「ナラヤナ数」というものを用いて N(h+w-1,h) で求められることが知られており N(n,k):=(1/n)(nCk)(nC(k-1)) となっています。 (もちろんこのことは解法1のアイディアを用いて証明することができます。) というわけで求める答えは (1/5)((5C3)*(5C2)) を2倍して 40 となるわけですね! なお、恥ずかしながら自分は行きと帰りで2倍になることを失念し ドヤ顔で20を送って何故か正解にならないぞとしばらくパニックになっていました…( |
プププランド
9月10日(木) 2:30:55
HomePage:正体不明(あんのうん) 49531 |
ゴンとも |
図で道に以下のように番号を振り
/(18)/(22)/(24) 横棒 (12)(17)(21)(23)縦棒 /(11)/(16)/(22) 横棒 (06)(10)(15)(19)縦棒 /(05)/(09)/(14) 横棒 (02)(04)(08)(13)縦棒 /(01)/(03)/(07) 横棒 十進Basicですべての経路を番号を振り出してみました!! FOR a=1 to 2 FOR b=3 to 6 if b=a then goto 110 if a=1 and (b<>3 and b<>4) then goto 110 if a=2 and (b<>5 and b<>6) then goto 110 FOR c=7 to 12 if c=a or c=b then goto 100 if b=3 and (c<>7 and c<>8) then goto 100 if b=4 and (c<>9 and c<>10) then goto 100 if b=5 and (c<>9 and c<>10) then goto 100 if b=6 and (c<>11 and c<>12) then goto 100 FOR d=13 to 18 if d=a or d=b or d=c then goto 90 if c=7 and d<>13 then goto 90 if c=8 and (d<>14 and d<>15) then goto 90 if c=9 and (d<>14 and d<>15) then goto 90 if c=10 and (d<>16 and d<>17) then goto 90 if c=11 and (d<>16 and d<>17) then goto 90 if c=12 and d<>18 then goto 90 FOR e=19 to 22 if e=a or e=b or e=c or e=d then goto 80 if d=13 and e<>19 then goto 80 if d=14 and e<>19 then goto 80 if d=15 and (e<>20 and e<>21) then goto 80 if d=16 and (e<>20 and e<>21) then goto 80 if d=17 and e<>22 then goto 80 if d=18 and e<>22 then goto 80 FOR f=23 to 24 if f=a or f=b or f=c or f=d or f=e then goto 70 if e=19 and f<>23 then goto 70 if e=20 and f<>23 then goto 70 if e=21 and f<>24 then goto 70 if e=22 and f<>24 then goto 70 FOR g=23 to 24 if g=a or g=b or g=c or g=d or g=e or g=f then goto 60 if f=23 and g<>24 then goto 60 if f=24 and g<>23 then goto 60 FOR h=19 to 22 if h=a or h=b or h=c or h=d or h=e or h=f or h=g then goto 50 if g=23 and (h<>19 and h<>20) then goto 50 if g=24 and (h<>21 and h<>22) then goto 50 FOR i=13 to 18 if i=a or i=b or i=c or i=d or i=e or i=f or i=g or i=h or (d+i=31 and d*i=15*16) then goto 40 if h=19 and (i<>13 and i<>14) then goto 40 if h=20 and (i<>15 and i<>16) then goto 40 if h=21 and (i<>15 and i<>16) then goto 40 if h=22 and (i<>17 and i<>18) then goto 40 FOR j=7 to 12 if j=a or j=b or j=c or j=d or j=e or j=f or j=g or j=h or j=i or (c+j=21 and c*j=110) or (c+j=17 and c*j=8*9) then goto 30 if i=13 and j<>7 then goto 30 if i=14 and (j<>8 and j<>9) then goto 30 if i=15 and (j<>8 and j<>9) then goto 30 if i=16 and (j<>10 and j<>11) then goto 30 if i=17 and (j<>10 and j<>11) then goto 30 if i=18 and j<>12 then goto 30 FOR k=3 to 6 if k=a or k=b or k=c or k=d or k=e or k=f or k=g or k=h or k=i or k=j or (b+k=9 and b*k=20) then goto 20 if j=7 and k<>3 then goto 20 if j=8 and k<>3 then goto 20 if j=9 and (k<>4 and k<>5) then goto 20 if j=10 and (k<>4 and k<>5) then goto 20 if j=11 and k<>6 then goto 20 if j=12 and k<>6 then goto 20 FOR l=1 to 2 if l=a or l=b or l=c or l=d or l=e or l=f or l=g or l=h or l=i or l=j or l=k then goto 10 if k=3 and l<>1 then goto 10 if k=4 and l<>1 then goto 10 if k=5 and l<>2 then goto 10 if k=6 and l<>2 then goto 10 PRINT s+1;"//";a;b;c;d;e;f;g;h;i;j;k;j;l let s=s+1 10 next l 20 next k 30 next j 40 next i 50 next h 60 next g 70 next f 80 next e 90 next d 100 next c 110 next b 120 next a END f9押して 1 // 1 3 7 13 19 23 24 21 15 9 5 9 2 2 // 1 3 7 13 19 23 24 21 16 10 5 10 2 3 // 1 3 7 13 19 23 24 21 16 11 6 11 2 4 // 1 3 7 13 19 23 24 22 17 10 5 10 2 5 // 1 3 7 13 19 23 24 22 17 11 6 11 2 6 // 1 3 7 13 19 23 24 22 18 12 6 12 2 7 // 1 3 8 14 19 23 24 21 16 10 5 10 2 8 // 1 3 8 14 19 23 24 21 16 11 6 11 2 9 // 1 3 8 14 19 23 24 22 17 10 5 10 2 10 // 1 3 8 14 19 23 24 22 17 11 6 11 2 11 // 1 3 8 14 19 23 24 22 18 12 6 12 2 12 // 1 3 8 15 20 23 24 22 17 10 5 10 2 13 // 1 3 8 15 20 23 24 22 17 11 6 11 2 14 // 1 3 8 15 20 23 24 22 18 12 6 12 2 15 // 1 4 9 14 19 23 24 21 16 11 6 11 2 16 // 1 4 9 14 19 23 24 22 17 11 6 11 2 17 // 1 4 9 14 19 23 24 22 18 12 6 12 2 18 // 1 4 9 15 20 23 24 22 17 11 6 11 2 19 // 1 4 9 15 20 23 24 22 18 12 6 12 2 20 // 1 4 10 16 20 23 24 22 18 12 6 12 2 21 // 2 5 9 15 21 24 23 19 13 7 3 7 1 22 // 2 5 10 16 21 24 23 19 13 7 3 7 1 23 // 2 5 10 16 21 24 23 19 14 8 3 8 1 24 // 2 5 10 17 22 24 23 19 13 7 3 7 1 25 // 2 5 10 17 22 24 23 19 14 8 3 8 1 26 // 2 5 10 17 22 24 23 20 15 8 3 8 1 27 // 2 6 11 16 21 24 23 19 13 7 3 7 1 28 // 2 6 11 16 21 24 23 19 14 8 3 8 1 29 // 2 6 11 16 21 24 23 19 14 9 4 9 1 30 // 2 6 11 17 22 24 23 19 13 7 3 7 1 31 // 2 6 11 17 22 24 23 19 14 8 3 8 1 32 // 2 6 11 17 22 24 23 19 14 9 4 9 1 33 // 2 6 11 17 22 24 23 20 15 8 3 8 1 34 // 2 6 11 17 22 24 23 20 15 9 4 9 1 35 // 2 6 12 18 22 24 23 19 13 7 3 7 1 36 // 2 6 12 18 22 24 23 19 14 8 3 8 1 37 // 2 6 12 18 22 24 23 19 14 9 4 9 1 38 // 2 6 12 18 22 24 23 20 15 8 3 8 1 39 // 2 6 12 18 22 24 23 20 15 9 4 9 1 40 // 2 6 12 18 22 24 23 20 16 10 4 10 1 |
豊川市
9月10日(木) 4:09:10
MAIL:fttnm528@ybb.ne.jp 49532 |
ゴンとも |
#49532
すみません自己レスで PRINT s+1;"//";a;b;c;d;e;f;g;h;i;j;k;j;l でなく PRINT s+1;"//";a;b;c;d;e;f;g;h;i;j;k;lに変えないと 経路が重複してしまって訂正しました!! 図で道に以下のように番号を振り /(18)/(22)/(24) 横棒 (12)(17)(21)(23)縦棒 /(11)/(16)/(22) 横棒 (06)(10)(15)(19)縦棒 /(05)/(09)/(14) 横棒 (02)(04)(08)(13)縦棒 /(01)/(03)/(07) 横棒 十進Basicですべての経路を番号を振り出してみました!! FOR a=1 to 2 FOR b=3 to 6 if b=a then goto 110 if a=1 and (b<>3 and b<>4) then goto 110 if a=2 and (b<>5 and b<>6) then goto 110 FOR c=7 to 12 if c=a or c=b then goto 100 if b=3 and (c<>7 and c<>8) then goto 100 if b=4 and (c<>9 and c<>10) then goto 100 if b=5 and (c<>9 and c<>10) then goto 100 if b=6 and (c<>11 and c<>12) then goto 100 FOR d=13 to 18 if d=a or d=b or d=c then goto 90 if c=7 and d<>13 then goto 90 if c=8 and (d<>14 and d<>15) then goto 90 if c=9 and (d<>14 and d<>15) then goto 90 if c=10 and (d<>16 and d<>17) then goto 90 if c=11 and (d<>16 and d<>17) then goto 90 if c=12 and d<>18 then goto 90 FOR e=19 to 22 if e=a or e=b or e=c or e=d then goto 80 if d=13 and e<>19 then goto 80 if d=14 and e<>19 then goto 80 if d=15 and (e<>20 and e<>21) then goto 80 if d=16 and (e<>20 and e<>21) then goto 80 if d=17 and e<>22 then goto 80 if d=18 and e<>22 then goto 80 FOR f=23 to 24 if f=a or f=b or f=c or f=d or f=e then goto 70 if e=19 and f<>23 then goto 70 if e=20 and f<>23 then goto 70 if e=21 and f<>24 then goto 70 if e=22 and f<>24 then goto 70 FOR g=23 to 24 if g=a or g=b or g=c or g=d or g=e or g=f then goto 60 if f=23 and g<>24 then goto 60 if f=24 and g<>23 then goto 60 FOR h=19 to 22 if h=a or h=b or h=c or h=d or h=e or h=f or h=g then goto 50 if g=23 and (h<>19 and h<>20) then goto 50 if g=24 and (h<>21 and h<>22) then goto 50 FOR i=13 to 18 if i=a or i=b or i=c or i=d or i=e or i=f or i=g or i=h or (d+i=31 and d*i=15*16) then goto 40 if h=19 and (i<>13 and i<>14) then goto 40 if h=20 and (i<>15 and i<>16) then goto 40 if h=21 and (i<>15 and i<>16) then goto 40 if h=22 and (i<>17 and i<>18) then goto 40 FOR j=7 to 12 if j=a or j=b or j=c or j=d or j=e or j=f or j=g or j=h or j=i or (c+j=21 and c*j=110) or (c+j=17 and c*j=8*9) then goto 30 if i=13 and j<>7 then goto 30 if i=14 and (j<>8 and j<>9) then goto 30 if i=15 and (j<>8 and j<>9) then goto 30 if i=16 and (j<>10 and j<>11) then goto 30 if i=17 and (j<>10 and j<>11) then goto 30 if i=18 and j<>12 then goto 30 FOR k=3 to 6 if k=a or k=b or k=c or k=d or k=e or k=f or k=g or k=h or k=i or k=j or (b+k=9 and b*k=20) then goto 20 if j=7 and k<>3 then goto 20 if j=8 and k<>3 then goto 20 if j=9 and (k<>4 and k<>5) then goto 20 if j=10 and (k<>4 and k<>5) then goto 20 if j=11 and k<>6 then goto 20 if j=12 and k<>6 then goto 20 FOR l=1 to 2 if l=a or l=b or l=c or l=d or l=e or l=f or l=g or l=h or l=i or l=j or l=k then goto 10 if k=3 and l<>1 then goto 10 if k=4 and l<>1 then goto 10 if k=5 and l<>2 then goto 10 if k=6 and l<>2 then goto 10 PRINT s+1;"//";a;b;c;d;e;f;g;h;i;j;k;l let s=s+1 10 next l 20 next k 30 next j 40 next i 50 next h 60 next g 70 next f 80 next e 90 next d 100 next c 110 next b 120 next a END 1 // 1 3 7 13 19 23 24 21 15 9 5 2 2 // 1 3 7 13 19 23 24 21 16 10 5 2 3 // 1 3 7 13 19 23 24 21 16 11 6 2 4 // 1 3 7 13 19 23 24 22 17 10 5 2 5 // 1 3 7 13 19 23 24 22 17 11 6 2 6 // 1 3 7 13 19 23 24 22 18 12 6 2 7 // 1 3 8 14 19 23 24 21 16 10 5 2 8 // 1 3 8 14 19 23 24 21 16 11 6 2 9 // 1 3 8 14 19 23 24 22 17 10 5 2 10 // 1 3 8 14 19 23 24 22 17 11 6 2 11 // 1 3 8 14 19 23 24 22 18 12 6 2 12 // 1 3 8 15 20 23 24 22 17 10 5 2 13 // 1 3 8 15 20 23 24 22 17 11 6 2 14 // 1 3 8 15 20 23 24 22 18 12 6 2 15 // 1 4 9 14 19 23 24 21 16 11 6 2 16 // 1 4 9 14 19 23 24 22 17 11 6 2 17 // 1 4 9 14 19 23 24 22 18 12 6 2 18 // 1 4 9 15 20 23 24 22 17 11 6 2 19 // 1 4 9 15 20 23 24 22 18 12 6 2 20 // 1 4 10 16 20 23 24 22 18 12 6 2 21 // 2 5 9 15 21 24 23 19 13 7 3 1 22 // 2 5 10 16 21 24 23 19 13 7 3 1 23 // 2 5 10 16 21 24 23 19 14 8 3 1 24 // 2 5 10 17 22 24 23 19 13 7 3 1 25 // 2 5 10 17 22 24 23 19 14 8 3 1 26 // 2 5 10 17 22 24 23 20 15 8 3 1 27 // 2 6 11 16 21 24 23 19 13 7 3 1 28 // 2 6 11 16 21 24 23 19 14 8 3 1 29 // 2 6 11 16 21 24 23 19 14 9 4 1 30 // 2 6 11 17 22 24 23 19 13 7 3 1 31 // 2 6 11 17 22 24 23 19 14 8 3 1 32 // 2 6 11 17 22 24 23 19 14 9 4 1 33 // 2 6 11 17 22 24 23 20 15 8 3 1 34 // 2 6 11 17 22 24 23 20 15 9 4 1 35 // 2 6 12 18 22 24 23 19 13 7 3 1 36 // 2 6 12 18 22 24 23 19 14 8 3 1 37 // 2 6 12 18 22 24 23 19 14 9 4 1 38 // 2 6 12 18 22 24 23 20 15 8 3 1 39 // 2 6 12 18 22 24 23 20 15 9 4 1 40 // 2 6 12 18 22 24 23 20 16 10 4 1 |
豊川市
9月10日(木) 4:21:35
MAIL:fttnm528@ybb.ne.jp 49533 |
鯨鯢(Keigei) |
縦の道m本,横の道n本の場合は
(m+n−3)!・(m+n−4)!/{(m−1)!・(m−2)!・(n−1)!・(n−2)!} 通りであり、 m=n=4 のとき、40通りになります。 詳しくは、https://okayadokary.blog.fc2.com/blog-entry-3465.html |
9月10日(木) 5:01:47
49534 |
「数学」小旅行 |
とりあえず、「エレファントなやり方」で。。。。
エレガントなやり方はこれから、掲示板を拝見して勉強させていただきます。 |
9月10日(木) 5:49:58
49535 |
ハラギャーテイ |
残念ながら認証だよりでした |
山口市
9月10日(木) 6:26:17
HomePage:制御工学にチャレンジ 49536 |
蜻蛉 |
とりあえず数え上げました |
9月10日(木) 8:15:08
49537 |
今年から高齢者 |
#49530。ありがとうございます。
前回の、掲示板も読み直しました。 でも、状況の把握ができず(能力不足)、理解不能です。 |
9月10日(木) 8:44:21
49538 |
「数学」小旅行 |
#49531
なるほど、そう考えるといいのですね!! 有難うございます。 |
9月10日(木) 11:00:21
49539 |
しおぱぱ |
左上半分を進むパターン6通りのそれぞれに
帰りのパターンを計算して2倍で求めました。 |
9月10日(木) 13:00:37
49540 |
にこたん |
交差点を見落としました。 |
超ど田舎
9月10日(木) 16:04:57
49541 |
吉川 マサル |
第330回のこと、完全に忘れてました。そして、自分の書き込みもしばらく「???」でした。笑 |
Mac
9月10日(木) 16:54:23
HomePage:算チャレ 49542 |
ゴンとも |
#49533
自己レスですみません訂正で・・・ 図で道に以下のように番号を振り が3行目の22を20に訂正等して以下 /(18)/(22)/(24)カレー店 横道 (12)(17)(21)(23) 縦道 /(11)/(16)/(20) 横道 (06)(10)(15)(19) 縦道 /(05)/(09)/(14) 横道 (02)(04)(08)(13) 縦道 S(01)/(03)/(07) 横道 |
豊川市
9月10日(木) 17:00:00
MAIL:fttnm528@ybb.ne.jp 49543 |
SECOND |
! #49522 algebra さんのアルゴリズムを 十進BASIC で<10ms
!右から始めて上に終る、又は、上から始めて右に終る 〇 往復。 !右から始めて右に終る、又は、上から始めて上に終る × 不可。 !一段上がるのに、4通りが3段(y1,y2,y3)、最短距離(y1≦y2≦y3) !帰り道(w1,w2,w3) この条件で y と w が接触しない「シラミ潰し」 !------------------------------------------ FOR y1=2 TO 4 FOR y2=y1 TO 4 LET y3=4 !-- PRINT "! 行き 帰り" LET w1=1 FOR w2=1 TO MIN(y1,y2)-1 FOR w3=w2 TO MIN(y2,y3)-1 LET n=n+1 PRINT USING"!###) # # # # # #": n,y1,y2,y3 ,w1,w2,w3 NEXT w3 NEXT w2 !-- NEXT y2 NEXT y1 PRINT "! 行き帰りを逆にして2倍=";n*2 |
9月10日(木) 19:03:55
49544 |
おすまん |
相変わらず「エレファントな」な解法と思いきや、#49522 algebraさまと
同じ着想で、そんなに筋は悪くなかったと知ってビックリ(笑) #49535 「数学」小旅行さま 早速、ありがとうございます(^^ 鯨鯢(Keigei) さま 自力で解くことができました♪ 鯨鯢(Keigei) さん |
somewhere in the world
9月12日(土) 20:21:45
49545 |
おすまん |
↓
#49534 鯨鯢(Keigei)さま でしたm(_ _)m 書き込み記事の訂正ができないのは、個人のPC環境によるのでしょうか…? > マサルさま |
somewhere in the world
9月13日(日) 1:03:53
49546 |
M |
Pythonで力わざで解をえました、スタートの地点の座標を(0,0)、x軸、y軸のどちらかに1を加え(3,3)まで行ったら戻ってくる、通った座標をリストに入れて重複がないもののみをピックアップ、最後にその個数を数えています。
import random import numpy as np import collections def has_duplicates2(seq): seen = [] unique_list = [x for x in seq if x not in seen and not seen.append(x)] return len(seq) != len(unique_list) def get_duplicate_list(seq): seen = [] return [x for x in seq if not seen.append(x) and seen.count(x) == 2] fin = [] for i in range (100000): path = np.empty((0,2), int) p = [0,0] l = [0,0,0,1,1,1] for n in range (6): a = random.choice(l) l.remove(a) if a == 0: p[0]=p[0]+1 else: p[1]=p[1]+1 path=np.append(path,np.array([p]),axis=0) l = [0,0,0,1,1,1] for n in range (6): a = random.choice(l) l.remove(a) if a == 0: p[0]=p[0]-1 else: p[1]=p[1]-1 path=np.append(path,np.array([p]),axis=0) path_final = path.tolist() if has_duplicates2(path_final) == False: fin.append(path_final) print(len(get_duplicate_list(fin))) |
9月13日(日) 15:01:57
49547 |
「数学」小旅行 |
なんかいい方法がないかなあ?と思って、かんがえたのが、以下の通り。
東西の移動を0、北移動を1、南移動をー1として、行きを[0,0,0,1,1,1]の順列として、 帰りを[0,0,0,-1,-1,-1]の順列とします。行きの最後が移動が0のときは、行きと 帰りがぶつからないのは同じ回数の移動の和がずっと負の数のままのときです。Rubyで書いてみました。 行きの最後が北移動の場合も同数だけあるので、下のプログラムで出た数を2倍して答とします。 n=0;[0,0,0,1,1,1].permutation.uniq.each{|x|[0,0,0,-1,-1,-1].permutation.uniq.each\ {|y| n+=1 if (x.first(1).sum+y.first(1).sum)<0&&(x.first(2).sum+y.first(2).sum<0)\ &&(x.first(3).sum+y.first(3).sum<0)&&(x.first(4).sum+y.first(4).sum<0)\ &&(x.first(5).sum+y.first(5).sum<0)}};p n |
9月14日(月) 16:46:27
49548 |
SECOND |
#49544 訂正できないので、、放置してました MIN() は不要です、悩んだ方 すみません。
FOR y1=2 TO 4 FOR y2=y1 TO 4 FOR w2=1 TO y1-1 FOR w3=w2 TO y2-1 LET n=n+1 NEXT w3 NEXT w2 NEXT y2 NEXT y1 PRINT n*2 |
9月15日(火) 21:45:54
49549 |