from pwn import * import itertools #context(os="linux", arch="i386", log_level="debug") import random import time io=remote('localhost',12345) io.recvuntil('vel1!\n') content = eval(io.recvline().strip().decode()) print(content) print(type(content)) defchange_row(map, pos, n): #用处不大,只是方便我检查 for i inrange(0, n): ifmap[pos][i] == 1: map[pos][i] = 0 else: map[pos][i] = 1
defchange_col(map, pos, n): #用处不大,只是方便我检查 for i inrange(0, n): ifmap[i][pos] == 1: map[i][pos] = 0 else: map[i][pos] = 1 defshow_map(map, n): #用处不大,只是方便我检查 for i inrange(0, n): for j inrange(0, n): ifmap[i][j] == 1: print("⬜", end=" ") else: print("⬛", end=" ") print() defcount(map): count = 0 for row inmap: for col in row: if col == 1: count += 1 SIZE = len(map) return count if count < SIZE * SIZE - count else SIZE * SIZE - count deftryflip(map): SIZE = len(map) combinations = [combo for r inrange(SIZE) for combo in itertools.combinations(range(SIZE), r)] pnt_count = SIZE * SIZE//2 temp_map = map final_map = temp_map for combo_r in combinations: for r in combo_r: change_row(temp_map, r, SIZE) for combo_c in combinations: for c in combo_c: change_col(temp_map, c, SIZE) now_count = count(temp_map) #print(now_count) if now_count < pnt_count: pnt_count = now_count final_map = [items[:] for items in temp_map[:] ] #show_map(final_map, SIZE) else: continue print(pnt_count) print(final_map) num=0 for i in final_map: for j in i: if j ==0: num=num+1 else: num=num-1 if num >0: for m inrange(SIZE): for n inrange(SIZE): if final_map[m][n] == 1: solution=f'{m+1}{n+1}' print(solution) io.sendline(bytes(solution.encode())) io.recvuntil('纵坐标:') else: for m inrange(SIZE): for n inrange(SIZE): if final_map[m][n] == 0: solution = f'{m + 1}{n + 1}' print(solution) io.sendline(bytes(solution.encode())) io.recvuntil('纵坐标:')