กราฟ *** ameoba **** เป็นต้นไม้ชนิดหนึ่งที่มีโหนดทั้งหมดมีค่าตั้งแต่ 0 ถึงจำนวนเต็มที่ไม่ใช่ค่าลบ N และโหนดใด ๆ ที่มีค่า x <N เชื่อมต่อกับ x + 1 โหนดที่แตกต่างที่มีค่า x + 1
กราฟ Ameoba สำหรับ N = 3: (หมายถึง A 3 )

โปรดทราบว่า 2 ของไม่ได้รับอนุญาตให้แบ่งปันใด ๆ ของ 3; สิ่งที่สามสามต้อง "เป็น" ต่อแต่ละ 2
ท้าทาย
งานของคุณคือการ "เหนี่ยว" กราฟ ameoba เหล่านี้แบบ inductively ในตาราง 2 มิติโดยลดระยะห่างระหว่างโหนดแมนฮัตตันอย่างโลภ:
- กรณีฐาน: 0
0เป็นเพียงกราฟ - ขั้นตอนอุปนัย: N + 1ถูกสร้างขึ้นโดยซ้ำวาง N +1 ใหม่มูลค่าโหนดใกล้เคียงเป็นไปได้ที่จะไม่มีค่าในโหนดเอที่มีอยู่ไม่มีโครงสร้าง (สามารถปิดได้มากที่สุดเนื่องจากอาจมีการเติมจุดที่ใกล้ที่สุดแล้ว)
สำหรับขั้นตอนอุปนัยขั้นตอนทั่วไปที่คุณต้องปฏิบัติตามคือ:
for each existing node P with value N:
for each new N+1 valued node Q you need to connect to P: //this loops N+1 times
find the set of vacant spots that are minimally distant from P //by Manhattan distance
place Q in any of these vacant spots
(โพรซีเดอร์อื่นที่มีเอาต์พุตที่ไม่สามารถแยกออกได้นั้นใช้ได้)
ตัวอย่างการเติบโตสำหรับ A 4 :
A0 is always the same:
0
For A1 I happen to put the 1 to the right of the 0 (it has to go on one of the 4 open sides):
01
For A2 I happen to put the two 2's above and to the right of the 1:
2
012
For A3 I find that one of the six 3's I must place cannot be directly next to a 2, so I put in one of the next closest places:
3
323
0123
33 <-- this 3 is distance two away from its 2
The process continues in A4. Note that I'm iterating over each 3 and placing four 4's next to it or as close as possible, then moving to the next 3 (the order of 3's does not matter):
444
443444
4323444
4012344
44334
4444
44
Always keep in mind that nodes cannot be "shared".
โปรแกรม
โปรแกรมที่คุณเขียนจะต้องมีตัวเลขตั้งแต่ 0 ถึง 8 (รวมแล้ว) และส่งออกกราฟ ameoba ที่ถูกต้องของมันโดยใช้รูปแบบการเจริญเติบโตอุปนัยที่อธิบายข้างต้น
สิ่งที่เกิดขึ้นเกิน 8 นั้นไม่สำคัญ
(A 8มี 46234 โหนดซึ่งผลักดันมันสิ่งที่เกินกว่า8จะไกลเกินไปขอบคุณ Martin Büttnerสำหรับการสังเกตสิ่งนี้)
อินพุตควรมาจาก stdin หรือบรรทัดคำสั่งและเอาต์พุตควรไปที่ stdout หรือไฟล์
ตัวอย่าง (ถ่ายโดยตรงจากด้านบน)
Input: 0
Output:
0
Input: 1
Output:
01
Input: 2
Output:
2
012
Input: 3
Output:
3
323
0123
33
Input: 4
Output:
444
443444
4323444
4012344
44334
4444
44
* กราฟประเภทนี้อาจมีชื่ออยู่แล้ว ฉันยอมรับว่าฉันเพิ่งสร้างมันขึ้นมา ;)