翻转后的棋盘

# coding utf8
# python3
# 题目:翻转后的棋盘
#   在 4×4 的棋盘上摆满了黑白棋子,黑白两色的位置和数目随机
#   其中,左上角坐标为 (1,1),右下角坐标为 (4,4)
#   现在依次有一些翻转操作,要对一些给定支点坐标为中心的上下左右四个棋子的颜色进行翻作
# 请计算出翻转后的棋盘颜色

# 给定两个数组 A和f 分别为初始棋盘和翻转位置。
# 其中翻转位置共有3个

# python qipan_recover.py -A \[\[0,0,1,1\],\[1,0,1,0\],\[0,1,1,0\],\[0,0,1,0\]\] -f \[\[2,2\],\[3,3\],\[4,4\]\]

import sys, getopt

def resover(status, station):
    x = station[0] - 1
    y = station[1] - 1
    if x - 1 >= 0:
        if status[x-1][y] == 0:
            status[x-1][y] = 1
        else:
            status[x-1][y] = 0
    if x + 1 < 4:
        if status[x+1][y] == 0:
            status[x+1][y] = 1
        else:
            status[x+1][y] = 0
    if y - 1 >= 0:
        if status[x][y-1] == 0:
            status[x][y-1] = 1
        else:
            status[x][y-1] = 0
    if y + 1 < 4:
        if status[x][y+1] == 0:
            status[x][y+1] = 1
        else:
            status[x][y+1] = 0
    return status


if __name__ == "__main__":
    opts, args = getopt.getopt(sys.argv[1:], "A:f:")
    for op, value in opts:
        if op == "-A":
            start_status = eval(value)
        elif op == "-f":
            station = eval(value)
    print(start_status)
    print(station)
    for s in station:
        start_status = resover(start_status, s)
    print (start_status)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值