1725. 组队井字游戏

摘要
Title: 1725. 组队井字游戏
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

1725. 组队井字游戏

  • 题意

    见原题

  • 思路

    枚举所有 横行、竖列、对角线即可,最后运用哈希表进行判重和计数即可

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    from collections import Counter, defaultdict
    ans = []
    g = []

    for _ in range(3): #横行
    s = input()
    d = Counter(s)
    ans.append(d)
    g.append(s)

    for j in range(3): #纵行
    d = Counter()
    for i in range(3):
    d[g[i][j]] += 1
    ans.append(d)

    d = Counter()
    for i in range(3): #正对角线
    d[g[i][i]] += 1
    ans.append(d)

    d = Counter()
    for i in range(3): #反对角线
    d[g[i][3 - i - 1]] += 1
    ans.append(d)

    st = defaultdict(int)
    cnt1, cnt2 = 0, 0
    for d in ans:
    s = ""
    for key in sorted(d.keys()):
    s += key
    if len(d) == 1 and st[s] == 0:
    cnt1 += 1
    st[s] += 1
    if len(d) == 2 and st[s] == 0:
    cnt2 += 1
    st[s] += 1

    print(cnt1)
    print(cnt2)
使用搜索:谷歌必应百度