#P4536. [CQOI2007] 三角形

    ID: 3475 远端评测题 500ms 250MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>字符串2007重庆各省省选递归深度优先搜索,DFS

[CQOI2007] 三角形

Description

Draw an equilateral triangle and connect the midpoints of its three sides to obtain four triangles, denoted T1,T2,T3,T4T_1, T_2, T_3, T_4, as shown in Figure 1.

Apply the same subdivision to the first three triangles to obtain 1212 smaller triangles: $T_{11}, T_{12}, T_{13}, T_{14}, T_{21}, T_{22}, T_{23}, T_{24}, T_{31}, T_{32}, T_{33}, T_{34}$, as shown in Figure 2.

Continue subdividing the triangles whose indices end with 1,2,31, 2, 3... The resulting fractal is called the Sierpinski triangle.

If triangle BB does not contain triangle AA, and one entire edge of AA is a part of an edge of BB, then we say AA “rests on” an edge of BB. For example, T12T_{12} rests on T14T_{14} and T4T_4, but does not rest on T32T_{32}.

Given a triangle in the Sierpinski triangle, find all the triangles it “rests on”.

Input Format

The input contains a single line: the index of a triangle. It starts with T followed by nn digits from 11 to 44. Only the last digit may be 44.

Output Format

Output one triangle index per line, sorted in lexicographical ascending order.

T312
T314
T34
T4

Hint

Constraints: For 100%100\% of the testdata, 1n501 \le n \le 50.

Translated by ChatGPT 5